From 1e970e0207a601983753bfd095df8e0ffaf9f8a9 Mon Sep 17 00:00:00 2001 From: Amman Pasha <67511337+ammanpashasc@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:03:49 +0500 Subject: [PATCH] fix uri encoding issue (#21) --- package.json | 2 +- src/utils/outputJsonFiles.ts | 12 +++++++++--- src/utils/urlReplace.ts | 5 ++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e40e304..916dd05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metadata-tool", - "version": "1.4.2", + "version": "1.4.3", "description": "", "main": "index.ts", "scripts": { diff --git a/src/utils/outputJsonFiles.ts b/src/utils/outputJsonFiles.ts index 59f916c..76552bb 100644 --- a/src/utils/outputJsonFiles.ts +++ b/src/utils/outputJsonFiles.ts @@ -57,7 +57,9 @@ export async function outputJsonFiles( const defaultTokenFileName = (data.factory.tokenUriTemplate == '{serial_number}' ? '{serial_number}' : defaultTokenHash) + '.json'; - const defaultTokenUrl = config.environmentUrl + '/' + config.collectionName + '/' + defaultTokenFileName; + const defaultTokenUrl = encodeURI( + config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + defaultTokenFileName + ); defaultToken = { hash: defaultTokenHash, @@ -73,7 +75,9 @@ export async function outputJsonFiles( const factory: HashUrl = { hash: factoryHash, - url: config.environmentUrl + '/' + config.collectionName + '/' + factoryHash + '.json', + url: encodeURI( + config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + factoryHash + '.json' + ), }; const tokens: Array = []; @@ -93,7 +97,9 @@ export async function outputJsonFiles( const tokenFileName = (data.factory.tokenUriTemplate == '{serial_number}' ? token.serialNumber : tokenHash) + '.json'; - const tokenUrl = config.environmentUrl + '/' + config.collectionName + '/' + tokenFileName; + const tokenUrl = encodeURI( + config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + tokenFileName + ); tokens.push({ serialNumber: token.serialNumber, hash: tokenHash, url: tokenUrl }); } diff --git a/src/utils/urlReplace.ts b/src/utils/urlReplace.ts index 1bcd294..5f10cad 100644 --- a/src/utils/urlReplace.ts +++ b/src/utils/urlReplace.ts @@ -26,10 +26,9 @@ export async function replaceUrls( const splitString = typedData.uris[i].split('.'); const extension = splitString[splitString.length - 1]; - const finalURL = new URL( - `${environmentURL}/${collectionName.replace(/ /g, '')}/${typedData.integrity?.hash}.${extension}` + const finalURL = encodeURI( + `${environmentURL}/${collectionName.replace(/\s/g, '')}/${typedData.integrity?.hash}.${extension}` ) - .toString() // To remove any query params (if they exist on any external urls) from the output url (output url in this case is the url of S3/Wasabi buckets) // This will fix, for eg: // input url ---> https://www.somewebsite.com/5000.jpg?width=1200&quality=85&auto=format&fit=max&token=0c4de651644de5fe939d8dbd6b14ba66