* Returns a [[FetchGatewayFunc]] for fetching content from a standard * IPFS gateway hosted at %%baseUrl%%.
(baseUrl)
| 54 | * IPFS gateway hosted at %%baseUrl%%. |
| 55 | */ |
| 56 | function 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 | } |
| 71 | const Gateways = { |
| 72 | "data": dataGatewayFunc, |
| 73 | "ipfs": getIpfsGatewayFunc("https:/\/gateway.ipfs.io/ipfs/") |
no outgoing calls
no test coverage detected