Skip to content

Commit 6322f8d

Browse files
committed
ipfs protocol prefix works
1 parent 90b1448 commit 6322f8d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/resolve.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
9494
// check to see if the link has the ipfs:// or ipns:// protocol/scheme
9595
else if ((uri as string).startsWith("ipfs://") || (uri as string).startsWith("ipns://")) {
9696

97+
const cidWithOptionalPath = (uri as string).substring(8);
98+
9799
// check to see if the CID after the ipfs protocal/scheme is valid
98-
const cidWithOptionalPath = (uri as string).substring(7);
99100
if (!isIPFS.cid(cidWithOptionalPath) && !isIPFS.cidPath(cidWithOptionalPath)) {
100101
throw new Error(`The uri (${uri}) passed in was malformed.`);
101102
}
@@ -107,6 +108,7 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
107108
}
108109

109110
gatewaySuffix = `/${protocol}/${cidWithOptionalPath}`;
111+
110112
}
111113

112114
// check to see if the uri is just a regular url that we can request

src/test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ describe("Tests the ipfs-race library.", () => {
3030
expect(await response.json(), urlResolvedFrom).to.deep.equal(testCidWithPathResult)
3131
});
3232

33+
it("ipfs protocol with no path", async () => {
34+
const {response, urlResolvedFrom} = await resolve(`ipfs:///${testCidWithNoPath}`);
35+
expect(await response.json(), urlResolvedFrom).to.deep.equal(testCidWithNoPathResult)
36+
});
37+
38+
it("ipfs protocol with path", async () => {
39+
const {response, urlResolvedFrom} = await resolve(`ipfs:///${testCidWithPath}`);
40+
expect(await response.json(), urlResolvedFrom).to.deep.equal(testCidWithPathResult)
41+
});
42+
3343
it("check that each default ipfs gateway to be a valid url", () => {
3444
for (const url of defaultIpfsGateways) {
3545
expect(isValidHttpUrl(url)).to.be.true;

0 commit comments

Comments
 (0)