Skip to content

Commit

Permalink
fix: return just gateway url if no cid provided
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla authored and agentofuser committed May 17, 2019
1 parent cc1c34d commit 98e55d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/gateway.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function getGatewayUrl(cid, gatewayProvider = 'ipfs') {
if (!cid) {
throw new Error('getGatewayUrl expects to be called with a valud IPFS CID')
}
const gateways = {
ipfs: 'https://ipfs.io',
infura: 'https://ipfs.infura.io',
pinata: 'https://gateway.pinata.cloud',
}
const origin = gateways[gatewayProvider] || gateways['ipfs']
if (!cid) {
return origin
}
return `${origin}/ipfs/${cid}`
}

Expand Down
8 changes: 4 additions & 4 deletions test/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ test('get http gateway url for a cid on pinata', t => {
t.is(actual, expected)
})

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

0 comments on commit 98e55d4

Please sign in to comment.