Skip to content

Commit

Permalink
Add try catch to CID parse
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Aug 28, 2023
1 parent 555699e commit 56d1738
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/utils/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export function getIpfsContentUrl(

if (uri.startsWith('http')) return uri

const ipfsCid = CID.parse(uri)
if (!ipfsCid) return uri

const isCbor = ipfsCid.code === CID_KIND.CBOR
if (isCbor) {
return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/api/v0/dag/get?arg=${uri}`)
}
return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/ipfs/${uri}`)
try {
const ipfsCid = CID.parse(uri)
if (!ipfsCid) return uri

const isCbor = ipfsCid.code === CID_KIND.CBOR
if (isCbor) {
return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/api/v0/dag/get?arg=${uri}`)
}
return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/ipfs/${uri}`)
} catch {}

return uri
}

export function getCidFromMetadataLink(link: string) {
Expand Down

0 comments on commit 56d1738

Please sign in to comment.