-
Notifications
You must be signed in to change notification settings - Fork 10
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 #143 from nation3/fix/141
Fix/141
- Loading branch information
Showing
7 changed files
with
77 additions
and
41 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 |
---|---|---|
|
@@ -68,4 +68,4 @@ export const TopBar = () => { | |
</div> | ||
</TopBarGrid> | ||
); | ||
}; | ||
}; |
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,43 +1,16 @@ | ||
import { Web3Storage } from "web3.storage"; | ||
import { pack } from "ipfs-car/pack"; | ||
import { CarReader } from "@ipld/car"; | ||
|
||
import { NFTStorage, Blob } from "nft.storage"; | ||
const ipfsGateway = "https://w3s.link/ipfs"; | ||
|
||
export const IPFSUriToUrl = (uri: string) => { | ||
return `${ipfsGateway}/${uri.split("ipfs://").pop()}`; | ||
}; | ||
|
||
export const client = () => { | ||
const token = process.env.IPFS_API_TOKEN || process.env.NEXT_PUBLIC_IPFS_API_TOKEN; | ||
if (!token) { | ||
throw new Error("IPFS API token not found"); | ||
} | ||
return new Web3Storage({ token }); | ||
}; | ||
|
||
const objectToFile = (obj: object, filename: string) => { | ||
const blob = new Blob([JSON.stringify(obj)], { type: "application/json" }); | ||
|
||
return new File([blob], filename); | ||
}; | ||
|
||
const stringToFile = (str: string, filename: string) => { | ||
return new File([Buffer.from(str)], filename); | ||
}; | ||
const client = new NFTStorage({ | ||
token: process.env.NEXT_PUBLIC_NFTSTORAGE_KEY || "", | ||
}); | ||
|
||
export const preparePutToIPFS = async (data: string | object, filename?: string) => { | ||
const file = | ||
typeof data === "string" | ||
? stringToFile(data, filename || "file.md") | ||
: objectToFile(data, "data.json"); | ||
const { root, out } = await pack({ input: [file], wrapWithDirectory: false }); | ||
const cid = root.toString(); | ||
|
||
const d = new Blob([JSON.stringify(data)]); | ||
const put = async () => { | ||
const car = await CarReader.fromIterable(out); | ||
return client().putCar(car); | ||
return await client.storeBlob(d); | ||
}; | ||
|
||
return { cid, put }; | ||
return { put }; | ||
}; |
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