- New Import page: upload an export (with upload progress) or, when the server has a Last.fm API key, import straight from a Last.fm username; jobs list with live progress, counts, errors and cancelling - docker compose runs the import worker from the API image; the API image no longer sets PROMETHEUS_MULTIPROC_DIR (gunicorn.conf.py does, and other commands must not inherit multiprocess mode) - Prometheus scrapes the worker; Usage dashboard gains an Imports row; ImportWorkerDown and ImportJobsWaiting alerts - README and .env.example document imports and LASTFM_API_KEY Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
// Shared page shell: site header, navigation, sign-in guard.
|
|
|
|
import { api, getToken, redirectToLogin, setToken } from "./api.js";
|
|
import { h, replace } from "./dom.js";
|
|
|
|
const NAV = [
|
|
["index.html", "Overview"],
|
|
["history.html", "History"],
|
|
["apps.html", "Apps"],
|
|
["sessions.html", "Sessions"],
|
|
["import.html", "Import"],
|
|
];
|
|
|
|
// Renders the header and returns the signed-in user (redirecting if there isn't one).
|
|
export async function signedInPage(active) {
|
|
if (!getToken()) {
|
|
redirectToLogin();
|
|
return new Promise(() => {}); // navigation is under way
|
|
}
|
|
const header = document.getElementById("site-header");
|
|
replace(header, brand(), nav(active));
|
|
const user = await api("/auth/me");
|
|
header.append(
|
|
h(
|
|
"div",
|
|
{ class: "account" },
|
|
h("span", { class: "account-name" }, user.username),
|
|
h("button", { type: "button", class: "link-button", onclick: signOut }, "Sign out"),
|
|
),
|
|
);
|
|
return user;
|
|
}
|
|
|
|
export function publicPage() {
|
|
replace(document.getElementById("site-header"), brand());
|
|
}
|
|
|
|
function brand() {
|
|
return h("a", { class: "brand", href: "index.html" }, h("span", { class: "brand-mark", "aria-hidden": "true" }), "Scrobbler");
|
|
}
|
|
|
|
function nav(active) {
|
|
return h(
|
|
"nav",
|
|
{ "aria-label": "Main" },
|
|
h(
|
|
"ul",
|
|
{},
|
|
NAV.map(([href, label]) =>
|
|
h("li", {}, h("a", { href, "aria-current": href === active ? "page" : false }, label)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
async function signOut() {
|
|
try {
|
|
await api("/auth/logout", { method: "POST" });
|
|
} finally {
|
|
setToken(null);
|
|
location.href = "login.html";
|
|
}
|
|
}
|