nft.storage
Version:
A client library for the https://nft.storage/ service. It provides a convenient interface for working with the HTTP API from a web browser or Node.js
1 lines • 1.56 kB
Source Map (JSON)
{"version":3,"file":"gateway.cjs","sources":["../../src/gateway.js"],"sourcesContent":["export const GATEWAY = new URL('https://nftstorage.link/')\n\n/**\n * @typedef {string|URL} GatewayURL Base URL of an IPFS Gateway e.g. https://dweb.link/ or https://ipfs.io/\n * @typedef {{ gateway?: GatewayURL }} GatewayURLOptions\n */\n\n/**\n * Convert an IPFS URL (starting ipfs://) to a gateway URL (starting https://)\n * that can be used in a webpage. If the passed URL is not an IPFS URL it is\n * returned as a new URL object with no further changes.\n *\n * @param {string|URL} url An IPFS URL e.g. ipfs://bafy.../path\n * @param {GatewayURLOptions} [options] Options that allow customization of the gateway used.\n * @returns {URL} An IPFS gateway URL e.g. https://nftstorage.link/ipfs/bafy.../path\n */\nexport const toGatewayURL = (url, options = {}) => {\n const gateway = options.gateway || GATEWAY\n url = new URL(String(url))\n return url.protocol === 'ipfs:'\n ? new URL(`/ipfs/${url.href.slice('ipfs://'.length)}`, gateway)\n : url\n}\n"],"names":[],"mappings":";;;;AAAY,MAAC,OAAO,GAAG,IAAI,GAAG,CAAC,0BAA0B,EAAC;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,KAAK;AACnD,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,QAAO;AAC5C,EAAE,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC;AAC5B,EAAE,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO;AACjC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AACnE,MAAM,GAAG;AACT;;;;;"}