From: Ardis Lu Date: Wed, 25 Feb 2026 07:40:14 +0000 (-0800) Subject: Refactor to simplify and flatten conditionals X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=83952d1449a6d2a0f6bfadf04a52c43f75ebc33b;p=solc-metadata Refactor to simplify and flatten conditionals --- diff --git a/index.js b/index.js index 4a382a6..e3d485f 100644 --- a/index.js +++ b/index.js @@ -219,19 +219,17 @@ function calculateCID(metadata) { * @returns {Promise} `Promise` that resolves to a `Response` object. */ function fetchCID(cid, ipfs) { - let response; - if (cid[0] === 'Q') { // v0 - response = fetch(`${ipfs.origin}/ipfs/${cid}${ipfs.search}`); + // CID v0 + if (cid[0] === 'Q') { + return fetch(`${ipfs.origin}/ipfs/${cid}${ipfs.search}`); } - else { // v1 - if (ipfs.host.split('.')[0] === 'ipfs') { - response = fetch(`${ipfs.protocol}//${cid}.${ipfs.host}${ipfs.pathname}${ipfs.search}`); - } - else { - response = fetch(`${ipfs.protocol}//${cid}.ipfs.${ipfs.host}${ipfs.pathname}${ipfs.search}`); - } + + // CID v1 + if (ipfs.host.split('.')[0] === 'ipfs') { // Hostname already includes ipfs subdomain + return fetch(`${ipfs.protocol}//${cid}.${ipfs.host}${ipfs.pathname}${ipfs.search}`); } - return response; + + return fetch(`${ipfs.protocol}//${cid}.ipfs.${ipfs.host}${ipfs.pathname}${ipfs.search}`); } export { fetchBytecode, detectLanguage, extractCBOR, decodeCBOR, calculateCID, fetchCID };