From 0becba4b673931689dbcb13e80306b65da26ba7d Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Sat, 9 Dec 2023 17:00:44 +0100 Subject: [PATCH 1/2] fix: Repair IPFS decoding in lsp-factory when using custom authenticated gateway. --- .tool-versions | 1 + src/lib/helpers/uploader.helper.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..0094556 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nodejs 16.14.2 diff --git a/src/lib/helpers/uploader.helper.ts b/src/lib/helpers/uploader.helper.ts index d039512..d9ff2e9 100644 --- a/src/lib/helpers/uploader.helper.ts +++ b/src/lib/helpers/uploader.helper.ts @@ -191,11 +191,14 @@ export function formatIPFSUrl(ipfsGateway: IPFSGateway, ipfsHash: string) { ipfsUrl = ipfsGateway.endsWith('/') ? `${ipfsGateway}${ipfsHash}` : `${ipfsGateway}/${ipfsHash}`; + } else if ( + ipfsGateway.url && + (typeof ipfsGateway.url === 'string' || ipfsGateway.url instanceof URL) + ) { + const url = new URL(ipfsGateway.url); + ipfsUrl = new URL(`/ipfs/${ipfsHash}`, url).toString(); } else { - const protocol = ipfsGateway?.host ?? 'https'; - const host = ipfsGateway?.host ?? '2eff.lukso.dev'; - - ipfsUrl = `${[protocol]}://${host}/ipfs/${ipfsHash}`; + throw new Error('IPFS gateway as Multiaddr is currently not supported'); } return ipfsUrl; From 2ae904ad6565d9194fb264ef2a104022f055691f Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Sat, 9 Dec 2023 17:25:48 +0100 Subject: [PATCH 2/2] fix: Add default api for ipfs. --- src/lib/helpers/uploader.helper.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers/uploader.helper.ts b/src/lib/helpers/uploader.helper.ts index d9ff2e9..1fefa08 100644 --- a/src/lib/helpers/uploader.helper.ts +++ b/src/lib/helpers/uploader.helper.ts @@ -186,20 +186,24 @@ export function isMetadataEncoded(metdata: string): boolean { export function formatIPFSUrl(ipfsGateway: IPFSGateway, ipfsHash: string) { let ipfsUrl: string; - if (typeof ipfsGateway === 'string') { ipfsUrl = ipfsGateway.endsWith('/') ? `${ipfsGateway}${ipfsHash}` : `${ipfsGateway}/${ipfsHash}`; } else if ( - ipfsGateway.url && + ipfsGateway?.url && (typeof ipfsGateway.url === 'string' || ipfsGateway.url instanceof URL) ) { const url = new URL(ipfsGateway.url); ipfsUrl = new URL(`/ipfs/${ipfsHash}`, url).toString(); - } else { + } else if (ipfsGateway?.host) { + const url = new URL(ipfsGateway.host); + url.protocol = 'https:'; + ipfsUrl = new URL(`/ipfs/${ipfsHash}`, url).toString(); + } else if (ipfsGateway?.url) { throw new Error('IPFS gateway as Multiaddr is currently not supported'); + } else { + ipfsUrl = new URL(`/ipfs/${ipfsHash}`, 'https://api.universalprofile.cloud').toString(); } - return ipfsUrl; }