Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

Refactor sanitizeDStorageUrl (#5652)

authored by yoginth.com and committed by

GitHub ff44755b 17513560

+11 -9
+11 -9
packages/helpers/sanitizeDStorageUrl.ts
··· 1 1 import { IPFS_GATEWAY, STORAGE_NODE_URL } from "@hey/data/constants"; 2 2 3 - const sanitizeDStorageUrl = (hash?: string): string => { 4 - if (!hash) { 3 + const sanitizeDStorageUrl = (url?: string): string => { 4 + if (!url) { 5 5 return ""; 6 6 } 7 7 8 8 const ipfsGateway = `${IPFS_GATEWAY}/`; 9 9 10 - let link = hash.replace(/^Qm[1-9A-Za-z]{44}/gm, `${IPFS_GATEWAY}/${hash}`); 11 - link = link.replace("https://ipfs.io/ipfs/", ipfsGateway); 12 - link = link.replace("ipfs://ipfs/", ipfsGateway); 13 - link = link.replace("ipfs://", ipfsGateway); 14 - link = link.replace("lens://", `${STORAGE_NODE_URL}/`); 15 - link = link.replace("ar://", "https://gateway.arweave.net/"); 10 + if (/^Qm[1-9A-Za-z]{44}/.test(url)) { 11 + return `${ipfsGateway}${url}`; 12 + } 16 13 17 - return link; 14 + return url 15 + .replace("https://ipfs.io/ipfs/", ipfsGateway) 16 + .replace("ipfs://ipfs/", ipfsGateway) 17 + .replace("ipfs://", ipfsGateway) 18 + .replace("lens://", `${STORAGE_NODE_URL}/`) 19 + .replace("ar://", "https://gateway.arweave.net/"); 18 20 }; 19 21 20 22 export default sanitizeDStorageUrl;