iuna-downloads.js (3188B)
1 (function () { 2 var rawVersion = window.IUNA_DOWNLOADS_VERSION || ""; 3 var version = rawVersion.replace(/^v/, ""); 4 var tag = "v" + version; 5 var base = "/downloads/"; 6 7 var artifacts = [ 8 { 9 label: "Linux CLI", 10 title: "Linux x86_64", 11 description: "Command-line node and wallet UI server.", 12 file: "iuna-" + tag + "-linux-x86_64.tar.gz", 13 button: "Download tar.gz" 14 }, 15 { 16 label: "Linux CLI", 17 title: "Linux aarch64", 18 description: "Command-line node and wallet UI server for ARM64 Linux.", 19 file: "iuna-" + tag + "-linux-aarch64.tar.gz", 20 button: "Download tar.gz" 21 }, 22 { 23 label: "macOS desktop", 24 title: "Apple silicon", 25 description: "Desktop app bundle for macOS.", 26 file: "iuna-" + tag + "-macos-aarch64-desktop.app.zip", 27 button: "Download app.zip" 28 }, 29 { 30 label: "Windows desktop", 31 title: "Windows x86_64", 32 description: "Desktop installer for Windows.", 33 file: "iuna-" + tag + "-windows-x86_64-desktop-setup.exe", 34 button: "Download setup.exe" 35 } 36 ]; 37 38 function escapeHtml(value) { 39 return String(value).replace(/[&<>"']/g, function (character) { 40 return { 41 "&": "&", 42 "<": "<", 43 ">": ">", 44 '"': """, 45 "'": "'" 46 }[character]; 47 }); 48 } 49 50 function checkArtifact(artifact) { 51 return fetch(base + artifact.file, { method: "HEAD", cache: "no-store" }) 52 .then(function (response) { 53 if (!response.ok) { 54 return null; 55 } 56 57 return Object.assign({}, artifact, { 58 size: Number(response.headers.get("content-length")) 59 }); 60 }) 61 .catch(function () { 62 return null; 63 }); 64 } 65 66 function renderCards(files) { 67 var container = document.querySelector("[data-download-cards]"); 68 if (!container) { 69 return; 70 } 71 72 if (files.length === 0) { 73 container.innerHTML = '<article class="card"><span class="tag pending">Pending</span><h2>No artifacts yet</h2><p class="muted">Release files have not been uploaded for this version.</p></article>'; 74 return; 75 } 76 77 container.innerHTML = files.map(function (file) { 78 return [ 79 '<article class="card">', 80 '<span class="tag">' + escapeHtml(file.label) + '</span>', 81 '<h2>' + escapeHtml(file.title) + '</h2>', 82 '<p>' + escapeHtml(file.description) + '</p>', 83 '<p><a class="button" href="' + escapeHtml(base + file.file) + '">' + escapeHtml(file.button) + '</a></p>', 84 '</article>' 85 ].join(""); 86 }).join(""); 87 } 88 89 function hydrateStaticText() { 90 var versionNodes = document.querySelectorAll("[data-download-version]"); 91 var linuxFile = "iuna-" + tag + "-linux-x86_64.tar.gz"; 92 var linuxNodes = document.querySelectorAll("[data-linux-x86-file]"); 93 94 versionNodes.forEach(function (node) { 95 node.textContent = tag; 96 }); 97 linuxNodes.forEach(function (node) { 98 node.textContent = linuxFile; 99 }); 100 } 101 102 hydrateStaticText(); 103 Promise.all(artifacts.map(checkArtifact)).then(function (results) { 104 var files = results.filter(Boolean); 105 renderCards(files); 106 }); 107 }());