From 8c2d1503d9dedc7fc03a1bbaef4cd890c740260d Mon Sep 17 00:00:00 2001 From: Mark Paul Date: Wed, 27 Nov 2024 11:54:16 +1100 Subject: [PATCH] feature: on solana mininting, we allow the user to send their own custom ipfs gateway to see if this solves the image not appearing issue --- package.json | 2 +- src/cnft-sol-minter.ts | 11 +++++++--- src/common/mint-utils.ts | 46 +++++++++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 2072dfd..c685d10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.16", + "version": "3.8.0-alpha.17", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/cnft-sol-minter.ts b/src/cnft-sol-minter.ts index 0c42cf2..4b75b62 100644 --- a/src/cnft-sol-minter.ts +++ b/src/cnft-sol-minter.ts @@ -43,6 +43,7 @@ export class CNftSolMinter extends MinterSol { * - imgGenSet: [optional] the custom series layer set to influence the image generation service * - signatureNonce: [optional] a recent nonce from the marshal network that will be signed to produce solSignature * - solSignature: [optional] a solana signature of signatureNonce to prove creatorAddress ownership + * - useThisCustomIPFSGateway: [optional] a custom ipfs gateway to use for the img and json. where the CID goes in a {insertCIDHere} placeholder e.g. https://gateway.pinata.cloud/ipfs/{insertCIDHere}. * */ async mint( @@ -62,6 +63,7 @@ export class CNftSolMinter extends MinterSol { imgGenSet?: string; signatureNonce?: string; solSignature?: string; + useThisCustomIPFSGateway?: string; } ): Promise<{ imageUrl: string; @@ -81,7 +83,8 @@ export class CNftSolMinter extends MinterSol { imgGenBg, imgGenSet, signatureNonce, - solSignature + solSignature, + useThisCustomIPFSGateway } = options ?? {}; const tokenNameValidator = new StringValidator() @@ -160,7 +163,8 @@ export class CNftSolMinter extends MinterSol { const { imageOnIpfsUrl: imgOnIpfsUrl } = await storeToIpfsOnlyImg( nftStorageToken, - _imageFile + _imageFile, + useThisCustomIPFSGateway ); if (!imgOnIpfsUrl || imgOnIpfsUrl === '') { @@ -182,7 +186,8 @@ export class CNftSolMinter extends MinterSol { const { metadataIpfsUrl } = await storeToIpfsFullSolCNftMetadata( nftStorageToken, - cNftMetadataContent + cNftMetadataContent, + useThisCustomIPFSGateway ); if (!metadataIpfsUrl || metadataIpfsUrl === '') { diff --git a/src/common/mint-utils.ts b/src/common/mint-utils.ts index 5310f7c..ca7e054 100644 --- a/src/common/mint-utils.ts +++ b/src/common/mint-utils.ts @@ -62,7 +62,8 @@ export async function storeToIpfs( export async function storeToIpfsFullSolCNftMetadata( storageToken: string, - metadataStructureSolCNft: object + metadataStructureSolCNft: object, + useThisCustomIPFSGateway?: string ): Promise<{ metadataIpfsUrl: string }> { try { const metadataIpfsHash = await storeTraitsToIpfs( @@ -71,9 +72,23 @@ export async function storeToIpfsFullSolCNftMetadata( ); if (metadataIpfsHash) { - return { - metadataIpfsUrl: `https://ipfs.io/ipfs/${metadataIpfsHash}` - }; + if ( + useThisCustomIPFSGateway && + useThisCustomIPFSGateway.includes('https://') && + useThisCustomIPFSGateway.includes('{insertCIDHere}') + ) { + // user wanted to use a custom gateway + return { + metadataIpfsUrl: useThisCustomIPFSGateway.replace( + '{insertCIDHere}', + metadataIpfsHash + ) + }; + } else { + return { + metadataIpfsUrl: `https://ipfs.io/ipfs/${metadataIpfsHash}` + }; + } } else { return { metadataIpfsUrl: '' @@ -86,15 +101,30 @@ export async function storeToIpfsFullSolCNftMetadata( export async function storeToIpfsOnlyImg( storageToken: string, - image: Blob + image: Blob, + useThisCustomIPFSGateway?: string ): Promise<{ imageOnIpfsUrl: string }> { try { const imageHash = await storeImageToIpfs(image, storageToken); if (imageHash) { - return { - imageOnIpfsUrl: `https://ipfs.io/ipfs/${imageHash}` - }; + if ( + useThisCustomIPFSGateway && + useThisCustomIPFSGateway.includes('https://') && + useThisCustomIPFSGateway.includes('{insertCIDHere}') + ) { + // user wanted to use a custom gateway + return { + imageOnIpfsUrl: useThisCustomIPFSGateway.replace( + '{insertCIDHere}', + imageHash + ) + }; + } else { + return { + imageOnIpfsUrl: `https://ipfs.io/ipfs/${imageHash}` + }; + } } else { return { imageOnIpfsUrl: ''