Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Sep 10, 2024
1 parent d44492d commit 86db0f0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 79 deletions.
5 changes: 5 additions & 0 deletions misc/.versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stable_version": "23.05.4",
"versions_list": ["23.05.4", "19.07.10"],
"image_url_override": "https://downloads.openwrt.org"
}
16 changes: 5 additions & 11 deletions www/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@ var config = {
// Pre-selected version (optional)
default_version: "23.05.4",

// "demo": Demo mode - use local .overview.json from local misc/ folder
// "openwrt": Use versions and default_version from remote .versions.json file.
// Comment out to use versions and default_version from this file
mode: "demo",
// Image download URL (e.g. "https://downloads.openwrt.org")
image_url: "../misc",

// Image download URL (optional)
// when not at location pointed to by versions
image_url: "https://downloads.openwrt.org",

// insert snapshot versions (optional)
// Insert snapshot versions (optional)
//show_snapshots: true,

// 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_extra_packages: ["luci"],
asu_url: "https://sysupgrade.openwrt.org",
asu_extra_packages: ["luci"],
};
119 changes: 51 additions & 68 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,16 +736,14 @@ function setup_uci_defaults() {
};
}

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

async function init() {
Expand All @@ -757,73 +755,58 @@ async function init() {
show("#details_custom");
}

config.overview_urls = {};
config.image_urls = {};

if (config.mode == "demo") {
// demo setup with local .overview.json files
for (const version of config.versions) {
config.overview_urls[version] = `../misc/${version}`;
config.image_urls[version] = `${config.image_url}/releases/${version}`;
}
} else if (config.mode == "openwrt") {
// openwrt.org setup
let upstream_config = await fetch(config.image_url + "/.versions.json", {
cache: "no-cache",
let upstream_config = await fetch(config.image_url + "/.versions.json", {
cache: "no-cache",
})
.then((obj) => {
return obj.json();
})
.then((obj) => {
return obj.json();
})
.then((obj) => {
const versions = {};
const urls = {};
if (config.show_snapshots) {
obj.versions_list = addSnapshotVersions(obj.versions_list);
}
for (const version of obj.versions_list) {
.then((obj) => {
const versions = obj.versions_list.filter(
(version) =>
// 19.07.4 is the first version supporting JSON profiles
if (
version.localeCompare("19.07.4", undefined, {
numeric: true,
sensitivity: "base",
}) >= 0
) {
if (version == "SNAPSHOTS") {
// openwrt.org oddity
urls[version] = `${config.image_url}/snapshots/`;
} else {
urls[version] = `${config.image_url}/releases/${version}`;
}
}
}
version.localeCompare("19.07.4", undefined, {
numeric: true,
sensitivity: "base",
}) >= 0
);

return {
versions: versions,
default_version: obj.stable_version,
overview_urls: urls,
image_urls: urls,
};
});
if (config.show_snapshots) {
insertSnapshotVersions(versions);
}

if (config.version) {
console.warn("version from config.json is overwritten");
}
return {
versions: versions,
image_url_override: obj.image_url_override,
default_version: obj.stable_version,
};
});

if (config.default_version) {
console.warn(
"versions and default_version from config.json are overwritten"
);
}
if (config.version) {
console.warn("version from config.json is overwritten");
}

config.versions = upstream_config.versions;
config.default_version = upstream_config.default_version;
config.overview_urls = upstream_config.overview_urls;
config.image_urls = upstream_config.image_urls;
} else {
// standard behavior
for (const version of config.versions) {
config.overview_urls[version] = `${config.image_url}/releases/${version}`;
config.image_urls[version] = `${config.image_url}/releases/${version}`;
if (config.default_version) {
console.warn(
"default_version from config.json is overwritten"
);
}

config.versions ||= upstream_config.versions;
config.default_version ||= upstream_config.default_version;

const overview_url = config.image_url;
const image_url = upstream_config.image_url_override || config.image_url;
config.overview_urls = {};
config.image_urls = {};
for (const version of config.versions) {
if (version == "SNAPSHOTS") {
// openwrt.org oddity
config.overview_urls[version] = `${overview_url}/snapshots/`;
config.image_urls[version] = `${image_url}/snapshots/`;
} else {
config.overview_urls[version] = `${overview_url}/releases/${version}`;
config.image_urls[version] = `${image_url}/releases/${version}`;
}
}

Expand Down

0 comments on commit 86db0f0

Please sign in to comment.