export type GetApiIpfsGatewayIPFSPathArgs = {IPFS_path: string}; export type GetApiIpfsGatewayIPFSPathOptions = {baseUrl?: string | undefined, projectId?: string | undefined, fetch?: typeof fetch | undefined}; /** * Relay to an IPFS gateway * * GET /ipfs/gateway/{IPFS_path} */ export const getApiIpfsGatewayIPFSPath = async (args: GetApiIpfsGatewayIPFSPathArgs, options?: GetApiIpfsGatewayIPFSPathOptions) => { const {baseUrl = "https://cardano-mainnet.blockfrost.io/api/v0", fetch: fetchFn = fetch, projectId} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (projectId !== undefined) headers.set("project_id", projectId) const url = `${baseUrl.replace(/\/+$/, '')}/ipfs/gateway/${encodeURIComponent(String(args.IPFS_path))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };