MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / getIpfsGatewayFunc

Function getIpfsGatewayFunc

lib.commonjs/utils/fetch.js:56–70  ·  view source on GitHub ↗

* Returns a [[FetchGatewayFunc]] for fetching content from a standard * IPFS gateway hosted at %%baseUrl%%.

(baseUrl)

Source from the content-addressed store, hash-verified

54 * IPFS gateway hosted at %%baseUrl%%.
55 */
56function getIpfsGatewayFunc(baseUrl) {
57 async function gatewayIpfs(url, signal) {
58 try {
59 const match = url.match(reIpfs);
60 if (!match) {
61 throw new Error("invalid link");
62 }
63 return new FetchRequest(`${baseUrl}${match[2]}`);
64 }
65 catch (error) {
66 return new FetchResponse(599, "BAD REQUEST (invalid IPFS URI)", {}, null, new FetchRequest(url));
67 }
68 }
69 return gatewayIpfs;
70}
71const Gateways = {
72 "data": dataGatewayFunc,
73 "ipfs": getIpfsGatewayFunc("https:/\/gateway.ipfs.io/ipfs/")

Callers 2

fetch.jsFile · 0.70
createIpfsGatewayFuncMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected