Skip to content
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

fix: Repair ipfs decoding when using custom authenticated gateway. #246

Merged
merged 2 commits into from
Jan 5, 2024
Merged
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
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;
}
Loading