-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Oli Evans <[email protected]>
- Loading branch information
1 parent
b4c181f
commit cc1c34d
Showing
5 changed files
with
2,878 additions
and
1,720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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'] | ||
return `${origin}/ipfs/${cid}` | ||
} | ||
|
||
module.exports = getGatewayUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const test = require('ava') | ||
const httpGatewayUrl = require('../src/gateway') | ||
|
||
test('get http gateway url for a cid', t => { | ||
const expected = 'https://ipfs.io/ipfs/fakecid' | ||
const actual = httpGatewayUrl('fakecid') | ||
t.is(actual, expected) | ||
}) | ||
|
||
test('get http gateway url for a cid on infura', t => { | ||
const expected = 'https://ipfs.infura.io/ipfs/fakecid' | ||
const actual = httpGatewayUrl('fakecid', 'infura') | ||
t.is(actual, expected) | ||
}) | ||
|
||
test('get http gateway url for a cid on pinata', t => { | ||
const expected = 'https://gateway.pinata.cloud/ipfs/fakecid' | ||
const actual = httpGatewayUrl('fakecid', 'pinata') | ||
t.is(actual, expected) | ||
}) | ||
|
||
test('throw if no cid', t => { | ||
t.throws(() => { | ||
httpGatewayUrl() | ||
}) | ||
}) |
Oops, something went wrong.