Skip to content

Commit

Permalink
Merge pull request #251 from lukso-network/develop
Browse files Browse the repository at this point in the history
Sync main
  • Loading branch information
CallumGrindle committed Jan 5, 2024
2 parents a1e4bcf + 9f2ed4c commit e0058df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .tool-versions
@@ -0,0 +1 @@
nodejs 16.14.2
19 changes: 13 additions & 6 deletions src/lib/helpers/uploader.helper.ts
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 e0058df

Please sign in to comment.