UNPKG

estaminet

Version:

A set of WebComponents building on top of Statemint family of Polkadot parachains

31 lines (30 loc) 769 B
import { url } from "./utils/ipfs"; /** * IPFS implementation of `StorageResolver` leveraging IPFS gateways. */ export class IPFSGatewayStorageResolver { async resolve(data) { const ipfsUrl = url(data); if (ipfsUrl) { const res = await fetch(ipfsUrl); if (res.ok) { return await res.json(); } } return null; } } /** * @param resolvers * @param data * @returns the first answer returned by a resolver. Resolvers are tried in order */ export async function resolve(resolvers, data) { for (const resolver of resolvers.values()) { const content = await resolver.resolve(data); if (content) { return content; } } return null; }