Skip to content

fix: update ipfs gateway #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/ast/source/utils/uri.js.json
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,10 @@
}
},
"extra": {
"rawValue": "https://ipfs.kleros.io",
"raw": "'https://ipfs.kleros.io'"
"rawValue": "https://cdn.kleros.link",
"raw": "'https://cdn.kleros.link'"
},
"value": "https://ipfs.kleros.io"
"value": "https://cdn.kleros.link"
}
},
"consequent": {
Expand Down Expand Up @@ -7240,7 +7240,7 @@
"binop": null,
"updateContext": null
},
"value": "https://ipfs.kleros.io",
"value": "https://cdn.kleros.link",
"start": 510,
"end": 534,
"loc": {
Expand Down
2 changes: 1 addition & 1 deletion docs/file/src/utils/uri.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
case 'http':
break
case 'https': {
if (ipfsGateway === 'https://ipfs.kleros.io') preValidated = true
if (ipfsGateway === 'https://cdn.kleros.link') preValidated = true
break
} case 'fs':
// check to see if fs is appended by /ipfs/
Expand Down
2 changes: 1 addition & 1 deletion docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2492,7 +2492,7 @@
"__docId__": 116,
"kind": "file",
"name": "src/utils/uri.js",
"content": "/* eslint-disable no-fallthrough */\nexport const getURISuffix = uri => uri.split('/').pop()\n\nexport const getURIProtocol = uri => {\n const uriParts = uri.replace(':', '').split('/')\n switch (uri.substr(0, 1)) {\n case '/':\n return uriParts[1]\n default:\n return uriParts[0]\n }\n}\n\nexport const getHttpUri = (uri, ipfsGateway) => {\n const protocol = getURIProtocol(uri)\n let preValidated = false\n switch (protocol) {\n case 'http':\n break\n case 'https': {\n if (ipfsGateway === 'https://ipfs.kleros.io') preValidated = true\n break\n } case 'fs':\n // check to see if fs is appended by /ipfs/\n if (uri.includes('/ipfs/')) uri = uri.split(':/').pop()\n else throw new Error(`Unrecognized protocol ${protocol}`)\n case 'ipfs':\n // NOTE the current WIP standard for IPFS uris: https://github.com/ipfs/go-ipfs/issues/1678#issuecomment-157478515\n // :// -> :/\n uri = uri.replace('://', ':/')\n // NURI\n if (uri.substr(0, 5) === '/ipfs' || uri.substr(0, 5) === 'ipfs/') {\n if (uri.substr(0, 1) === '/') uri = uri.substr(1, uri.length - 1)\n uri = `${ipfsGateway}/${uri}`\n }\n // compatability scheme\n else if (uri.substr(0, 6) === 'ipfs:/')\n uri = `${ipfsGateway}/${uri.split(':/').pop()}`\n else throw new Error(`Unrecognized protocol ${protocol}`)\n\n preValidated = true\n break\n case 'ipns':\n // TODO we cannot validate these right now\n break\n default:\n throw new Error(`Unrecognized protocol ${protocol}`)\n }\n\n return {\n uri,\n preValidated\n }\n}\n",
"content": "/* eslint-disable no-fallthrough */\nexport const getURISuffix = uri => uri.split('/').pop()\n\nexport const getURIProtocol = uri => {\n const uriParts = uri.replace(':', '').split('/')\n switch (uri.substr(0, 1)) {\n case '/':\n return uriParts[1]\n default:\n return uriParts[0]\n }\n}\n\nexport const getHttpUri = (uri, ipfsGateway) => {\n const protocol = getURIProtocol(uri)\n let preValidated = false\n switch (protocol) {\n case 'http':\n break\n case 'https': {\n if (ipfsGateway === 'https://cdn.kleros.link') preValidated = true\n break\n } case 'fs':\n // check to see if fs is appended by /ipfs/\n if (uri.includes('/ipfs/')) uri = uri.split(':/').pop()\n else throw new Error(`Unrecognized protocol ${protocol}`)\n case 'ipfs':\n // NOTE the current WIP standard for IPFS uris: https://github.com/ipfs/go-ipfs/issues/1678#issuecomment-157478515\n // :// -> :/\n uri = uri.replace('://', ':/')\n // NURI\n if (uri.substr(0, 5) === '/ipfs' || uri.substr(0, 5) === 'ipfs/') {\n if (uri.substr(0, 1) === '/') uri = uri.substr(1, uri.length - 1)\n uri = `${ipfsGateway}/${uri}`\n }\n // compatability scheme\n else if (uri.substr(0, 6) === 'ipfs:/')\n uri = `${ipfsGateway}/${uri.split(':/').pop()}`\n else throw new Error(`Unrecognized protocol ${protocol}`)\n\n preValidated = true\n break\n case 'ipns':\n // TODO we cannot validate these right now\n break\n default:\n throw new Error(`Unrecognized protocol ${protocol}`)\n }\n\n return {\n uri,\n preValidated\n }\n}\n",
"static": true,
"longname": "/home/henrique/dev/kleros/archon/src/utils/uri.js",
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getHttpUri = (uri, ipfsGateway) => {
case 'http':
break
case 'https': {
if (ipfsGateway === 'https://ipfs.kleros.io') preValidated = true
if (ipfsGateway === 'https://cdn.kleros.link') preValidated = true
break
} case 'fs':
// check to see if fs is appended by /ipfs/
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/uri.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('URI', () => {
expect(uriData.uri).toEqual(testURI)
expect(uriData.preValidated).toBeFalsy()
})
it("https://ipfs.kleros.io", () => {
const testURI = "https://ipfs.kleros.io/ipfs/hash";
const trustedGateway = "https://ipfs.kleros.io";
it("https://cdn.kleros.link", () => {
const testURI = "https://cdn.kleros.link/ipfs/hash";
const trustedGateway = "https://cdn.kleros.link";

const uriData = getHttpUri(testURI, trustedGateway);
expect(uriData.uri).toEqual(testURI);
Expand Down
Loading