-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from StauroXYZ/lighthouse-storage
feat: Lighthouse storage + GW3 upload support
- Loading branch information
Showing
11 changed files
with
105 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import fetch, { Headers, Request, Response, FormData } from 'node-fetch' | ||
import fetch, { Headers, Request, Response, FormData, Blob } from 'node-fetch' | ||
|
||
if (!('fetch' in globalThis)) { | ||
Object.assign(globalThis, { fetch, Headers, Request, Response, FormData }) | ||
} | ||
|
||
if (!('Blob' in globalThis)) { | ||
Object.assign(globalThis, { Blob }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { DeployError } from '../errors.js' | ||
import { UploadFunction } from '../types.js' | ||
|
||
const providerName = 'Lighthouse' | ||
|
||
export const uploadOnLighthouse: UploadFunction = async ({ car, cid, name, token }) => { | ||
if (car) { | ||
const depotTokenRes = await fetch('https://data-depot.lighthouse.storage/api/auth/lighthouse_auth', { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}) | ||
const depotTokenJson = await depotTokenRes.json() | ||
|
||
if (!depotTokenRes.ok) throw new DeployError(providerName, depotTokenJson) | ||
|
||
const fd = new FormData() | ||
fd.append('file', car as Blob) | ||
const res = await fetch('https://data-depot.lighthouse.storage/api/upload/upload_files', { | ||
method: 'POST', | ||
body: fd, | ||
headers: { | ||
Authorization: `Bearer ${depotTokenJson.access_token}`, | ||
}, | ||
}) | ||
const json = await res.text() | ||
|
||
if (!res.ok) throw new DeployError(providerName, json) | ||
|
||
return { cid } | ||
} | ||
else { | ||
const res = await fetch(new URL('/api/lighthouse/pin', 'https://api.lighthouse.storage'), { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
cid, fileName: name, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}`, | ||
}, | ||
}) | ||
|
||
const json = await res.json() | ||
|
||
if (!res.ok) throw new DeployError(providerName, json.errors[0].message) | ||
|
||
return { cid } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters