Skip to content

Commit

Permalink
Merge pull request #246 from lukso-network/fix/repair-ipfs-decode
Browse files Browse the repository at this point in the history
fix: Repair ipfs decoding when using custom authenticated gateway.
  • Loading branch information
CallumGrindle authored Jan 5, 2024
2 parents 58edb58 + 2ae904a commit f55d0e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 16.14.2
19 changes: 13 additions & 6 deletions src/lib/helpers/uploader.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +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 &&
(typeof ipfsGateway.url === 'string' || ipfsGateway.url instanceof URL)
) {
const url = new URL(ipfsGateway.url);
ipfsUrl = new URL(`/ipfs/${ipfsHash}`, url).toString();
} 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 {
const protocol = ipfsGateway?.host ?? 'https';
const host = ipfsGateway?.host ?? '2eff.lukso.dev';

ipfsUrl = `${[protocol]}://${host}/ipfs/${ipfsHash}`;
ipfsUrl = new URL(`/ipfs/${ipfsHash}`, 'https://api.universalprofile.cloud').toString();
}

return ipfsUrl;
}

0 comments on commit f55d0e1

Please sign in to comment.