Explorar o código

pin list: add cid v1

Fabian Peter Hammerle hai 1 ano
pai
achega
657fb4028d
Modificáronse 1 ficheiros con 15 adicións e 4 borrados
  1. 15 4
      src/index.js

+ 15 - 4
src/index.js

@@ -5,10 +5,21 @@ const IPFS = require('ipfs');
 
 function create_pin_tag(node, cid) {
     const item = document.createElement('li');
-    const link = document.createElement('a');
-    link.href = "https://dweb.link/ipfs/" + cid.toString();
-    link.innerText = cid.toString();
-    item.appendChild(link);
+    // > If you can't decide between CIDv0 and CIDv1, consider choosing CIDv1
+    // > for your new project [...]. This is more future-proof and safe for use
+    // > in browser contexts.
+    // https://docs.ipfs.tech/concepts/content-addressing/#identifier-formats
+    Object.entries({
+        'CID v1': cid.toV1().toString(),
+        'CID v0': cid.toV0().toString(),
+    }).forEach(([label, cid_string]) => {
+        item.appendChild(document.createTextNode(label + ": "));
+        const link = document.createElement('a');
+        link.href = "https://ipfs.io/ipfs/" + cid_string;
+        link.innerText = cid_string.toString();
+        item.appendChild(link);
+        item.appendChild(document.createElement('br'));
+    });
     const unpinButton = document.createElement('button');
     unpinButton.innerText = 'unpin';
     unpinButton.onclick = async function() {