Skip to content

Commit

Permalink
encode collection name (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammanpashasc authored Feb 6, 2024
1 parent 1e970e0 commit 6143a01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metadata-tool",
"version": "1.4.3",
"version": "1.4.4",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down
28 changes: 19 additions & 9 deletions src/utils/outputJsonFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<SerialHashUrl> = [];
Expand All @@ -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 });
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/urlReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export async function replaceUrls<T>(

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
Expand Down

0 comments on commit 6143a01

Please sign in to comment.