diff --git a/app/services/uriPreview.server.ts b/app/services/uriPreview.server.ts index 8c295dd..303a93e 100644 --- a/app/services/uriPreview.server.ts +++ b/app/services/uriPreview.server.ts @@ -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;