Skip to content

Commit

Permalink
api: use upstream offered JSON files
Browse files Browse the repository at this point in the history
This is right now for testing only, however ideally we'd switch to
automatically generated JSON files instead of relying on the collect
script.

Signed-off-by: Paul Spooren <[email protected]>
  • Loading branch information
aparcar committed Jun 17, 2024
1 parent e0a7078 commit f38d80f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
11 changes: 7 additions & 4 deletions www/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ var config = {

// Path to were overview.json can be found
versions: {
"22.03.5": "../misc/22.03.5",
"19.07.10": "../misc/19.07.10",
"22.03.5": "https://downloads.openwrt.org/releases/22.03.5",
"19.07.10": "https://downloads.openwrt.org/releases/19.07.10",
},

// Show snapshots (optional)
show_snapshots: true,

// Pre-selected version (optional)
default_version: "22.03.5",

// Image download URL
image_url: "https://downloads.openwrt.org/",
image_url: "https://downloads.openwrt.org",

// Info link URL (optional)
info_url: "https://openwrt.org/start?do=search&id=toh&q={title} @toh",

// Attended Sysupgrade Server support (optional)
// asu_url: "https://sysupgrade.openwrt.org",
asu_url: "https://sysupgrade.openwrt.org",
// asu_extra_packages: [ "luci" ],
};
56 changes: 46 additions & 10 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function buildAsuRequest(request_hash) {
}

fetch(request_url, {
cache: "no-cache",
method: method,
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -528,11 +529,10 @@ function updateImages(mobj) {

if (mobj) {
const images = mobj.images;
let image_folder = config.image_url + mobj.image_path;

// ASU override
if ("asu_image_url" in mobj) {
image_folder = mobj.asu_image_url;
mobj.image_folder = mobj.asu_image_url;
}

const h3 = $("#downloads1 h3");
Expand All @@ -553,7 +553,7 @@ function updateImages(mobj) {
setValue("#image-version", mobj.version_number);
setValue("#image-code", mobj.version_code);
setValue("#image-date", mobj.build_at);
setValue("#image-folder", image_folder);
setValue("#image-folder", mobj.image_folder);

setValue(
"#image-info",
Expand Down Expand Up @@ -582,7 +582,7 @@ function updateImages(mobj) {
const extras2 = $("#download-extras2");

for (const image of images) {
const link = createLink(mobj, image, image_folder);
const link = createLink(mobj, image, mobj.image_folder);
const extra = createExtra(image);

const row = append(table1, "TR");
Expand All @@ -591,7 +591,7 @@ function updateImages(mobj) {
}

for (const image of images) {
const link = createLink(mobj, image, image_folder);
const link = createLink(mobj, image, mobj.image_folder);
const extra = createExtra(image);

links2.appendChild(link);
Expand Down Expand Up @@ -666,14 +666,17 @@ function setModel(overview, target, id) {
function changeModel(version, overview, title, base_url) {
const entry = overview.profiles[title];
if (entry) {
fetch(`${base_url}/${entry.target}/${entry.id}.json`, {
fetch(`${base_url}/targets/${entry.target}/profiles.json`, {
cache: "no-cache",
})
.then((obj) => {
return obj.json();
})
.then((mobj) => {
mobj["id"] = entry.id;
mobj["images"] = mobj["profiles"][entry.id]["images"];
mobj["titles"] = mobj["profiles"][entry.id]["titles"];
mobj["image_folder"] = `${base_url}/targets/${entry.target}/`;
updateImages(mobj);
current_device = {
version: version,
Expand Down Expand Up @@ -731,7 +734,7 @@ function setup_uci_defaults() {
};
}

function init() {
async function init() {
url_params = new URLSearchParams(window.location.search);

$("#ofs_version").innerText = ofs_version;
Expand All @@ -740,10 +743,43 @@ function init() {
show("#details_custom");
}

setupSelectList($("#versions"), Object.keys(config.versions), (version) => {
let versions = await fetch(config.image_url + "/.versions.json", {
cache: "no-cache",
})
.then((obj) => {
return obj.json();
})
.then((obj) => {
return obj.versions_list.filter(
(version) =>
// 19.07.4 is the first version supporting JSON profiles
version.localeCompare("19.07.4", undefined, {
numeric: true,
sensitivity: "base",
}) >= 0
);
});

console.log(versions);

if (config.show_snapshots) {
for (const version of versions.slice()) {
let branch = version.split(".").slice(0, -1).join(".") + "-SNAPSHOT";
if (!versions.includes(branch)) {
versions.push(branch);
}
}
versions.push("SNAPSHOTS");
}

setupSelectList($("#versions"), versions, (version) => {
// A new version was selected
let base_url = config.versions[version];
fetch(base_url + "/overview.json", { cache: "no-cache" })
let base_url = `${config.image_url}/releases/${version}`;
if (version == "SNAPSHOTS") {
base_url = `${config.image_url}/snapshots/`;
}

fetch(base_url + "/.overview.json", { cache: "no-cache" })
.then((obj) => {
return obj.json();
})
Expand Down

0 comments on commit f38d80f

Please sign in to comment.