From 6143a01dc4be7a7953b179c9f394d757d292560a Mon Sep 17 00:00:00 2001 From: Amman Pasha <67511337+ammanpashasc@users.noreply.github.com> Date: Tue, 6 Feb 2024 20:59:36 +0500 Subject: [PATCH] encode collection name (#22) --- package-lock.json | 4 ++-- package.json | 2 +- src/utils/outputJsonFiles.ts | 28 +++++++++++++++++++--------- src/utils/urlReplace.ts | 6 +++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index cc71e76..9242e7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "metadata-tool", - "version": "1.4.2", + "version": "1.4.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "metadata-tool", - "version": "1.4.2", + "version": "1.4.4", "license": "ISC", "dependencies": { "ajv": "^8.12.0", diff --git a/package.json b/package.json index 916dd05..59db78e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metadata-tool", - "version": "1.4.3", + "version": "1.4.4", "description": "", "main": "index.ts", "scripts": { diff --git a/src/utils/outputJsonFiles.ts b/src/utils/outputJsonFiles.ts index 76552bb..05fbc38 100644 --- a/src/utils/outputJsonFiles.ts +++ b/src/utils/outputJsonFiles.ts @@ -57,9 +57,12 @@ export async function outputJsonFiles( const defaultTokenFileName = (data.factory.tokenUriTemplate == '{serial_number}' ? '{serial_number}' : defaultTokenHash) + '.json'; - const defaultTokenUrl = encodeURI( - config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + defaultTokenFileName - ); + const defaultTokenUrl = + config.environmentUrl + + '/' + + encodeURIComponent(config.collectionName!.replace(/\s/g, '')) + + '/' + + defaultTokenFileName; defaultToken = { hash: defaultTokenHash, @@ -75,9 +78,13 @@ export async function outputJsonFiles( const factory: HashUrl = { hash: factoryHash, - url: encodeURI( - config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + factoryHash + '.json' - ), + url: + config.environmentUrl + + '/' + + encodeURIComponent(config.collectionName!.replace(/\s/g, '')) + + '/' + + factoryHash + + '.json', }; const tokens: Array = []; @@ -97,9 +104,12 @@ export async function outputJsonFiles( const tokenFileName = (data.factory.tokenUriTemplate == '{serial_number}' ? token.serialNumber : tokenHash) + '.json'; - const tokenUrl = encodeURI( - config.environmentUrl + '/' + config.collectionName?.replace(/\s/g, '') + '/' + tokenFileName - ); + const tokenUrl = + config.environmentUrl + + '/' + + encodeURIComponent(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 5f10cad..8842534 100644 --- a/src/utils/urlReplace.ts +++ b/src/utils/urlReplace.ts @@ -26,9 +26,9 @@ export async function replaceUrls( const splitString = typedData.uris[i].split('.'); const extension = splitString[splitString.length - 1]; - const finalURL = encodeURI( - `${environmentURL}/${collectionName.replace(/\s/g, '')}/${typedData.integrity?.hash}.${extension}` - ) + const finalURL = `${environmentURL}/${encodeURIComponent(collectionName.replace(/\s/g, ''))}/${ + typedData.integrity?.hash + }.${extension}` // 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