Skip to content

Commit

Permalink
fix: gateway url in client
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Feb 14, 2022
1 parent cf841bb commit c8bc5a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/gateway.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const GATEWAY = new URL('https://dweb.link/')
export const GATEWAY = new URL('https://nftstorage.link/')

/**
* @typedef {string|URL} GatewayURL Base URL of an IPFS Gateway e.g. https://dweb.link/ or https://ipfs.io/
Expand All @@ -12,7 +12,7 @@ export const GATEWAY = new URL('https://dweb.link/')
*
* @param {string|URL} url An IPFS URL e.g. ipfs://bafy.../path
* @param {GatewayURLOptions} [options] Options that allow customization of the gateway used.
* @returns {URL} An IPFS gateway URL e.g. https://dweb.link/ipfs/bafy.../path
* @returns {URL} An IPFS gateway URL e.g. https://nftstorage.link/ipfs/bafy.../path
*/
export const toGatewayURL = (url, options = {}) => {
const gateway = options.gateway || GATEWAY
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/gateway.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const filename = 'yesthisisdog.jpg'
describe('toGatewayURL', () => {
it('converts ipfs:// URL to a gateway URL', () => {
const ipfsURL = new URL(`ipfs://${cid}/${filename}`)
const gwURL = new URL(`https://dweb.link/ipfs/${cid}/${filename}`)
const gwURL = new URL(`https://nftstorage.link/ipfs/${cid}/${filename}`)
const result = toGatewayURL(ipfsURL)
assert.equal(result.href, gwURL.href)
})

it('converts ipfs:// URL (as string) to a gateway URL', () => {
const ipfsURLStr = `ipfs://${cid}/${filename}`
const gwURL = new URL(`https://dweb.link/ipfs/${cid}/${filename}`)
const gwURL = new URL(`https://nftstorage.link/ipfs/${cid}/${filename}`)
const result = toGatewayURL(ipfsURLStr)
assert.equal(result.href, gwURL.href)
})
Expand Down
8 changes: 4 additions & 4 deletions packages/client/test/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CarWriter } from '@ipld/car'
import * as dagJson from '@ipld/dag-json'
import { randomCar } from './helpers.js'

const DWEB_LINK = 'dweb.link'
const GATEWAY_LINK = 'nftstorage.link'

describe('client', () => {
const { AUTH_TOKEN, SERVICE_ENDPOINT } = process.env
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('client', () => {
assert.equal(embed.description, 'stuff')
assert.ok(embed.image instanceof URL)
assert.ok(embed.image.protocol, 'https:')
assert.ok(embed.image.host, DWEB_LINK)
assert.ok(embed.image.host, GATEWAY_LINK)

assert.equal(embed.properties.extra, 'meta')
assert.ok(Array.isArray(embed.properties.src))
Expand All @@ -490,11 +490,11 @@ describe('client', () => {
const [h2, b2] = /** @type {[URL, URL]} */ (embed.properties.src)
assert.ok(h2 instanceof URL)
assert.equal(h2.protocol, 'https:')
assert.equal(h2.host, DWEB_LINK)
assert.equal(h2.host, GATEWAY_LINK)

assert.ok(b2 instanceof URL)
assert.equal(b2.protocol, 'https:')
assert.equal(b2.host, DWEB_LINK)
assert.equal(b2.host, GATEWAY_LINK)
})

it('store with OpenSea extensions', async () => {
Expand Down

0 comments on commit c8bc5a7

Please sign in to comment.