mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 12:20:20 +01:00
This commit is contained in:
parent
43986ee86f
commit
74fc1036e6
|
|
@ -7,9 +7,7 @@ import {
|
|||
let IPFS_GATEWAY_URL = "";
|
||||
|
||||
export const IPFS_GATEWAY_URLS = [
|
||||
"https://<CID>.ipfs.cf-ipfs.com/",
|
||||
"https://<CID>.ipfs.dweb.link/",
|
||||
"https://cloudflare-ipfs.com/ipfs/<CID>/",
|
||||
"https://gateway.ipfs.io/ipfs/<CID>/",
|
||||
];
|
||||
|
||||
|
|
@ -65,11 +63,12 @@ export const getIpfsGatewayUrl = async (
|
|||
if (!IPFS_GATEWAY_URL) return "";
|
||||
}
|
||||
|
||||
const { pathname, protocol, search } = new URL(ipfsUrl);
|
||||
const { hostname, pathname, protocol, search } = new URL(ipfsUrl);
|
||||
|
||||
if (protocol !== "ipfs:") return "";
|
||||
|
||||
const [cid = "", ...path] = pathname.split("/").filter(Boolean);
|
||||
const fullPath = `${hostname}${pathname}`;
|
||||
const [cid = "", ...path] = fullPath.split("/").filter(Boolean);
|
||||
const { CID } = await import("multiformats");
|
||||
|
||||
return `${IPFS_GATEWAY_URL.replace(
|
||||
|
|
@ -82,17 +81,16 @@ export const getIpfsFileName = async (
|
|||
ipfsUrl: string,
|
||||
ipfsData: Buffer
|
||||
): Promise<string> => {
|
||||
const { pathname, searchParams } = new URL(ipfsUrl);
|
||||
const { hostname, pathname, searchParams } = new URL(ipfsUrl);
|
||||
const fileName = searchParams.get("filename");
|
||||
|
||||
if (fileName) return fileName;
|
||||
|
||||
const { fileTypeFromBuffer } = await import("file-type");
|
||||
const { ext = "" } = (await fileTypeFromBuffer(ipfsData)) || {};
|
||||
const fullPath = `${hostname}${pathname}`;
|
||||
|
||||
return `${pathname.split("/").filter(Boolean).join("_")}${
|
||||
ext ? `.${ext}` : ""
|
||||
}`;
|
||||
return `${fullPath.split("/").filter(Boolean).join("_")}${ext ? `.${ext}` : ""}`;
|
||||
};
|
||||
|
||||
export const getIpfsResource = async (ipfsUrl: string): Promise<Buffer> => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user