]> git.ardis.lu - solc-metadata/commitdiff
Refactor to simplify and flatten conditionals
authorArdis Lu <ardisglu@gmail.com>
Wed, 25 Feb 2026 07:40:14 +0000 (23:40 -0800)
committerArdis Lu <ardisglu@gmail.com>
Wed, 25 Feb 2026 07:40:14 +0000 (23:40 -0800)
index.js

index 4a382a696e43f581f6cb81013de4c3497d803934..e3d485f74ff0e4b04c1648c83c2d6f6e6db39cfa 100644 (file)
--- a/index.js
+++ b/index.js
@@ -219,19 +219,17 @@ function calculateCID(metadata) {
  * @returns {Promise<Response>} `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 };
This page took 0.045411 seconds and 4 git commands to generate.