Fixed previewing IPFS images in cloudflare

This commit is contained in:
Eric Allam
2022-06-07 13:49:40 +01:00
parent 6df767080a
commit bc5e5561c7
+11 -5
View File
@@ -159,11 +159,17 @@ function rewriteUrl(url: URL | string): URL {
// Rewrite the URL if it is a relative URL
if (unmodifiedUrl.protocol === "ipfs:") {
return new URL(
`https://ipfs.io/ipfs/${unmodifiedUrl.hostname}${
unmodifiedUrl.pathname.length > 0 ? `/${unmodifiedUrl.pathname}` : ""
}${unmodifiedUrl.search}`
);
if (unmodifiedUrl.hostname === "") {
return new URL(
`https://ipfs.io/ipfs/${unmodifiedUrl.pathname.substring(2)}`
);
} else {
return new URL(
`https://ipfs.io/ipfs/${unmodifiedUrl.hostname}${
unmodifiedUrl.pathname.length > 0 ? `/${unmodifiedUrl.pathname}` : ""
}${unmodifiedUrl.search}`
);
}
}
return unmodifiedUrl;