Created
May 4, 2024 14:32
-
-
Save martenc/56f52c6e1dca1f898f94f4465fa6e218 to your computer and use it in GitHub Desktop.
Parse IPFS json to get img url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
input to parse: | |
{"image":"ipfs://QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/de22e8bd5787802d7417009f647bb33b","name":"2 kilobytes low cost Token Eric #137"} | |
output: | |
https://cf-ipfs.com/ipfs/QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/72315d4fbdc4e2d96ea6777b67b5f8a8 | |
*/ | |
function convertIpfsUrl(ipfsUrl: string): string { | |
const cid = ipfsUrl.replace("ipfs://", ""); | |
const ipfsDomain = "cf-ipfs.com/ipfs"; | |
const transformedUrl = `https://${ipfsDomain}/${cid}`; | |
return transformedUrl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment