summaryrefslogtreecommitdiff
path: root/static/js/releases.js
blob: 2a6da0b0902aaa5f075bee62afcae854888aed88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT

const baseUrl = "https://releases.grapheneos.org/";
const devices = ["husky", "shiba", "felix", "tangorpro", "lynx", "cheetah", "panther", "bluejay", "raven", "oriole", "barbet", "redfin", "bramble", "sunfish", "coral", "flame"];
const channels = ["stable", "beta"];
const delayMs = 1000 * 60 * 5;

function updateLink(link, text, url) {
    link.innerText = text;
    link.setAttribute("href", url);
}

async function updateReleases() {
    const requests = [];

    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 factoryFilename = device + "-factory-" + metadata[0] + ".zip";
                const factoryUrl = baseUrl + factoryFilename;

                const updateFilename = device + "-ota_update-" + metadata[0] + ".zip";
                const updateUrl = baseUrl + updateFilename;

                const release = document.getElementById(device + "-" + channel);
                const links = release.getElementsByTagName("a");

                updateLink(links[1], metadata[0], "#" + metadata[0]);
                updateLink(links[2], factoryFilename, factoryUrl);
                updateLink(links[3], factoryFilename + ".sig", factoryUrl + ".sig");
                updateLink(links[4], updateFilename, updateUrl);
            }));
        }
    }

    await Promise.allSettled(requests);
    setTimeout(updateReleases, delayMs);
}

setTimeout(updateReleases, delayMs);

// @license-end