Skip to content

Commit 98e55d4

Browse files
olizillaagentofuser
authored andcommitted
fix: return just gateway url if no cid provided
License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>
1 parent cc1c34d commit 98e55d4

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/gateway.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function getGatewayUrl(cid, gatewayProvider = 'ipfs') {
2-
if (!cid) {
3-
throw new Error('getGatewayUrl expects to be called with a valud IPFS CID')
4-
}
52
const gateways = {
63
ipfs: 'https://ipfs.io',
74
infura: 'https://ipfs.infura.io',
85
pinata: 'https://gateway.pinata.cloud',
96
}
107
const origin = gateways[gatewayProvider] || gateways['ipfs']
8+
if (!cid) {
9+
return origin
10+
}
1111
return `${origin}/ipfs/${cid}`
1212
}
1313

test/gateway.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ test('get http gateway url for a cid on pinata', t => {
1919
t.is(actual, expected)
2020
})
2121

22-
test('throw if no cid', t => {
23-
t.throws(() => {
24-
httpGatewayUrl()
25-
})
22+
test('get just the http gateway url if no cid', t => {
23+
const expected = 'https://ipfs.io'
24+
const actual = httpGatewayUrl()
25+
t.is(actual, expected)
2626
})

0 commit comments

Comments
 (0)