Skip to content

Commit 37ec4ca

Browse files
authored
Jd/fix ipfs reolve scheme bug (thirdweb-dev#3241)
1 parent 558885a commit 37ec4ca

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.changeset/soft-meals-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
fix ipfs `resolveScheme` bug for v1 ipfs schemes

packages/thirdweb/src/utils/ipfs.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ describe("resolveScheme", () => {
1212
expect(url).toMatchInlineSnapshot(`"https://test.ipfscdn.io/ipfs/Qm..."`);
1313
});
1414

15+
it("should resolve ipfs scheme", () => {
16+
const client = createThirdwebClient({
17+
clientId: "test",
18+
});
19+
const uri =
20+
"ipfs://bafkreidi5y7afj5z4xrz7uz5rkg2mcsv2p2n4ui4g7q4k4ecdz65i2agou";
21+
const url = resolveScheme({ client, uri });
22+
expect(url).toMatchInlineSnapshot(
23+
`"https://test.ipfscdn.io/ipfs/bafkreidi5y7afj5z4xrz7uz5rkg2mcsv2p2n4ui4g7q4k4ecdz65i2agou"`,
24+
);
25+
});
26+
1527
it("should resolve ipfs scheme when passing a gateway override", () => {
1628
const client = createThirdwebClient({
1729
clientId: "test",

packages/thirdweb/src/utils/ipfs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function findIPFSCidFromUri(uri: string) {
6363
}
6464

6565
// first index of `/Qm` or `/bafy` in the uri (case insensitive)
66-
const firstIndex = uri.search(/\/(Qm|bafy)/i);
66+
const firstIndex = uri.search(/\/(Qm|baf)/i);
6767
// we start one character after the first `/` to avoid including it in the CID
6868
return uri.slice(firstIndex + 1);
6969
}

0 commit comments

Comments
 (0)