Add software version manifest management
This commit is contained in:
@@ -79,6 +79,7 @@ const els = {
|
||||
topicDev: document.querySelector("#topic-dev"),
|
||||
topicSecurity: document.querySelector("#topic-security"),
|
||||
playerStatus: document.querySelector("#player-status"),
|
||||
authLinks: [...document.querySelectorAll("[data-player-auth]")],
|
||||
};
|
||||
|
||||
function escapeHtml(value = "") {
|
||||
@@ -114,6 +115,10 @@ function getDownloadHref(item) {
|
||||
return `/api/software/${encodeURIComponent(item.id)}/download`;
|
||||
}
|
||||
|
||||
function getLoginHref(next = "/software.html") {
|
||||
return `login.html?next=${encodeURIComponent(next)}`;
|
||||
}
|
||||
|
||||
function iconMarkup(item) {
|
||||
const safeName = escapeHtml(item.name);
|
||||
if (item.iconUrl) {
|
||||
@@ -281,6 +286,16 @@ async function loadAuth() {
|
||||
state.authLoaded = true;
|
||||
render();
|
||||
}
|
||||
return state.player;
|
||||
}
|
||||
|
||||
async function ensurePlayer(next) {
|
||||
if (!state.authLoaded) {
|
||||
await loadAuth();
|
||||
}
|
||||
if (state.player) return true;
|
||||
window.location.href = getLoginHref(next);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function loadSoftware() {
|
||||
@@ -309,6 +324,23 @@ els.categoryButtons.forEach((button) => {
|
||||
});
|
||||
|
||||
els.refreshButton.addEventListener("click", loadSoftware);
|
||||
els.authLinks.forEach((link) => {
|
||||
link.addEventListener("click", async (event) => {
|
||||
const href = link.getAttribute("href") || "/software.html";
|
||||
const next = link.dataset.next || href;
|
||||
if (state.authLoaded && state.player) return;
|
||||
|
||||
event.preventDefault();
|
||||
const isAuthenticated = await ensurePlayer(next);
|
||||
if (!isAuthenticated) return;
|
||||
|
||||
if (href.startsWith("#")) {
|
||||
document.querySelector(href)?.scrollIntoView({ behavior: "smooth" });
|
||||
return;
|
||||
}
|
||||
window.location.href = href;
|
||||
});
|
||||
});
|
||||
els.playerStatus.addEventListener("click", async (event) => {
|
||||
if (!event.target.closest("#player-logout")) return;
|
||||
await fetch("/api/auth/logout", { method: "POST", headers: { Accept: "application/json" } });
|
||||
|
||||
Reference in New Issue
Block a user