From 3c535a4415f8a4bf118a81469b466dedaf4981d3 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Fri, 7 Jun 2024 03:38:34 -0700 Subject: [PATCH 1/2] fix(utils/ipfs): fix regular expression in findIPFSCidFromUri --- packages/thirdweb/src/utils/ipfs.test.ts | 12 ++++++++++++ packages/thirdweb/src/utils/ipfs.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) 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); } From d63cdb9ddcd52bbfb064c1166508b85aa07f2d1e Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Fri, 7 Jun 2024 03:39:11 -0700 Subject: [PATCH 2/2] fix: fix ipfs `resolveScheme` bug for v1 ipfs schemes --- .changeset/soft-meals-invite.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-meals-invite.md 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