diff --git a/example/node.js b/example/node.js index e43067f..d6463d7 100644 --- a/example/node.js +++ b/example/node.js @@ -37,9 +37,11 @@ avt }) .catch(console.log); -avt - .getHeader(ensName) +try { + avt + .getHeader(ensName, { jsdomWindow: jsdom }) .then(header => { console.log('header: ', header); }) .catch(console.log); +} catch {} diff --git a/package.json b/package.json index a5deac1..4a24ce2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "main": "dist/index.js", "module": "dist/index.esm.js", diff --git a/src/specs/erc1155.ts b/src/specs/erc1155.ts index 2b3143a..8b69fb0 100644 --- a/src/specs/erc1155.ts +++ b/src/specs/erc1155.ts @@ -62,7 +62,8 @@ export default class ERC1155 { 'base64' ).toString(); } - return JSON.parse(_resolvedUri); + const metadata = JSON.parse(_resolvedUri); + return { ...metadata, is_owner: isOwner }; } const marketplaceKey = getMarketplaceAPIKey(resolvedURI, options); diff --git a/src/specs/erc721.ts b/src/specs/erc721.ts index 0bc229a..965a93b 100644 --- a/src/specs/erc721.ts +++ b/src/specs/erc721.ts @@ -50,7 +50,7 @@ export default class ERC721 { 'base64' ).toString(); } - const metadata = JSON.parse(decodeURI(_resolvedUri)); + const metadata = JSON.parse(_resolvedUri); return { ...metadata, is_owner: isOwner }; } const response = await fetch( diff --git a/src/utils/resolveURI.ts b/src/utils/resolveURI.ts index 0cec0ec..5e01591 100644 --- a/src/utils/resolveURI.ts +++ b/src/utils/resolveURI.ts @@ -9,6 +9,7 @@ const IPNS_SUBPATH = '/ipns/'; const networkRegex = /(?ipfs:\/|ipns:\/|ar:\/)?(?\/)?(?ipfs\/|ipns\/)?(?[\w\-.]+)(?\/.*)?/; const base64Regex = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/; const dataURIRegex = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/; +const JSON_MIMETYPE = 'data:application/json;'; function _getImageMimeType(uri: string) { const base64Data = uri.replace(base64Regex, '$2'); @@ -49,11 +50,11 @@ function _isValidBase64(uri: string) { } const [header, str] = uri.split('base64,'); - - const mimeType = _getImageMimeType(uri); - - if (!mimeType || !header.includes(mimeType)) { - return false; + if (header != JSON_MIMETYPE) { + const mimeType = _getImageMimeType(uri); + if (!mimeType || !header.includes(mimeType)) { + return false; + } } // length must be multiple of 4