From 7b0fda4129e0c7a89e3ed9f3f6f699e536f77c1d Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 8 Feb 2021 04:19:29 -0500 Subject: [PATCH] keep releases listing dynamically updated --- static/js/releases.js | 60 +++++++++++++++++++++++++------------------ static/releases.html | 2 +- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/static/js/releases.js b/static/js/releases.js index 482f8ac5..7416ce0c 100644 --- a/static/js/releases.js +++ b/static/js/releases.js @@ -4,41 +4,51 @@ const baseUrl = "https://releases.grapheneos.org/"; const versionBaseUrl = "https://github.com/GrapheneOS/platform_manifest/releases/tag/"; const devices = ["redfin", "bramble", "sunfish", "coral", "flame", "bonito", "sargo", "crosshatch", "blueline", "taimen", "walleye"]; const channels = ["stable", "beta"]; +const delayMs = 1000 * 60 * 5; -for (const channel of channels) { - for (const device of devices) { - fetch(baseUrl + device + "-" + channel).then(response => { - if (!response.ok) { - return Promise.reject(); - } - return response.text(); - }).then(text => { - const metadata = text.trim().split(" "); +async function updateReleases() { + const requests = []; - const factoryFilename = device + "-factory-" + metadata[0] + ".zip"; - const factoryUrl = baseUrl + factoryFilename; + for (const channel of channels) { + for (const device of devices) { + requests.push(fetch(baseUrl + device + "-" + channel).then(response => { + if (!response.ok) { + return Promise.reject(); + } + return response.text(); + }).then(text => { + const metadata = text.trim().split(" "); - const updateFilename = device + "-ota_update-" + metadata[0] + ".zip"; - const updateUrl = baseUrl + updateFilename; + const factoryFilename = device + "-factory-" + metadata[0] + ".zip"; + const factoryUrl = baseUrl + factoryFilename; - const tag = metadata[2] + "." + metadata[0]; + const updateFilename = device + "-ota_update-" + metadata[0] + ".zip"; + const updateUrl = baseUrl + updateFilename; - const release = document.getElementById(device + "-" + channel); - const links = release.getElementsByTagName("a"); + const tag = metadata[2] + "." + metadata[0]; - links[1].innerText = tag; - links[1].setAttribute("href", versionBaseUrl + tag); + const release = document.getElementById(device + "-" + channel); + const links = release.getElementsByTagName("a"); - links[2].innerText = factoryFilename; - links[2].setAttribute("href", factoryUrl); + links[1].innerText = tag; + links[1].setAttribute("href", versionBaseUrl + tag); - links[3].innerText = factoryFilename + ".sig"; - links[3].setAttribute("href", factoryUrl + ".sig"); + links[2].innerText = factoryFilename; + links[2].setAttribute("href", factoryUrl); - links[4].innerText = updateFilename; - links[4].setAttribute("href", updateUrl); - }); + links[3].innerText = factoryFilename + ".sig"; + links[3].setAttribute("href", factoryUrl + ".sig"); + + links[4].innerText = updateFilename; + links[4].setAttribute("href", updateUrl); + })); + } } + + await Promise.allSettled(requests); + setTimeout(updateReleases, delayMs); } +updateReleases(); + // @license-end diff --git a/static/releases.html b/static/releases.html index 6f8a81f4..c5e26785 100644 --- a/static/releases.html +++ b/static/releases.html @@ -27,7 +27,7 @@ - +