diff --git a/.changeset/soft-meals-invite.md b/.changeset/soft-meals-invite.md new file mode 100644 index 00000000000..ff5141d0562 --- /dev/null +++ b/.changeset/soft-meals-invite.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +fix ipfs `resolveScheme` bug for v1 ipfs schemes diff --git a/packages/thirdweb/src/utils/ipfs.test.ts b/packages/thirdweb/src/utils/ipfs.test.ts index e25834bd332..896ed30cc33 100644 --- a/packages/thirdweb/src/utils/ipfs.test.ts +++ b/packages/thirdweb/src/utils/ipfs.test.ts @@ -12,6 +12,18 @@ describe("resolveScheme", () => { expect(url).toMatchInlineSnapshot(`"https://test.ipfscdn.io/ipfs/Qm..."`); }); + it("should resolve ipfs scheme", () => { + const client = createThirdwebClient({ + clientId: "test", + }); + const uri = + "ipfs://bafkreidi5y7afj5z4xrz7uz5rkg2mcsv2p2n4ui4g7q4k4ecdz65i2agou"; + const url = resolveScheme({ client, uri }); + expect(url).toMatchInlineSnapshot( + `"https://test.ipfscdn.io/ipfs/bafkreidi5y7afj5z4xrz7uz5rkg2mcsv2p2n4ui4g7q4k4ecdz65i2agou"`, + ); + }); + it("should resolve ipfs scheme when passing a gateway override", () => { const client = createThirdwebClient({ clientId: "test", diff --git a/packages/thirdweb/src/utils/ipfs.ts b/packages/thirdweb/src/utils/ipfs.ts index eef5a27e4cc..46c87ac6fae 100644 --- a/packages/thirdweb/src/utils/ipfs.ts +++ b/packages/thirdweb/src/utils/ipfs.ts @@ -63,7 +63,7 @@ export function findIPFSCidFromUri(uri: string) { } // first index of `/Qm` or `/bafy` in the uri (case insensitive) - const firstIndex = uri.search(/\/(Qm|bafy)/i); + const firstIndex = uri.search(/\/(Qm|baf)/i); // we start one character after the first `/` to avoid including it in the CID return uri.slice(firstIndex + 1); }