assetgraph-ipfs
IFPS-related assetgraph tools.
useGateway
Replaces all assets with links to an IPFS gateway. The assets will also be placed in the output in /ipfs/{hash}/{fileName}
so that they are properly pinned when the website is.
Warning: If the ipfsOptions
do not match what you use to add/pin/upload the website the assets may not be accessible by the hash used in the URL. Verify that you are using the correct configuration. This can be done by running ipfs ls /ipfs/$root_hash/ipfs
and verifying that column 1 (hash) and 3 (name) are the same for each entry.
import {useGateway} from "assetgraph-ipfs";
let assetgraph = new AssetGraph(...);
await assetgraphIpfs.useGateway(
g.findAssets({path: { $regex: /^\/assets\// }}),
{
crossorigin: false,
gatewayHost = "https://cloudflare-ipfs.com",
gatewayUrl = ({asset, cid, path}) => `https://ipfs.io/ipfs/${cid.toV0()}/${path}`,
ipfsOptions: {
chunker: "rabin",
},
referrerPolicy: "strict-origin-when-cross-origin",
rename: false,
sri: false,
})