- Plain HTML + vanilla JS modules, no build step; talks to /api/v1 with a bearer token and only ever inserts server data as text - Overview: now-playing dot-matrix display with live progress, totals, 30-day plays meter, top artists/tracks by period, recent plays - History (paged, grouped by day), Apps (create/delete, reveal/copy keys, player setup details), Sessions (revoke), sign-in approval page for the Last.fm desktop auth flow, sign in and registration - Light and dark themes, responsive to phone widths, vendored fonts (SIL OFL) so the UI has no third-party requests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
import { ApiError, api } from "./api.js";
|
|
import { errorBox, h, replace } from "./dom.js";
|
|
import { signedInPage } from "./layout.js";
|
|
|
|
const root = document.getElementById("approve");
|
|
const token = new URLSearchParams(location.search).get("token");
|
|
|
|
await signedInPage("");
|
|
|
|
if (!token) {
|
|
replace(root, h("h1", {}, "Nothing to approve"), h("p", { class: "lede" }, "This link is missing its token. Start signing in from your player again."));
|
|
} else {
|
|
try {
|
|
const info = await api(`/tokens/${encodeURIComponent(token)}`);
|
|
info.approved ? showApproved(info.app_name) : showRequest(info.app_name);
|
|
} catch (error) {
|
|
showProblem(error);
|
|
}
|
|
}
|
|
|
|
function showRequest(appName) {
|
|
const allow = h("button", { type: "button", class: "button" }, "Allow access");
|
|
allow.addEventListener("click", async () => {
|
|
allow.disabled = true;
|
|
try {
|
|
await api("/tokens/approve", { method: "POST", body: { token } });
|
|
showApproved(appName);
|
|
} catch (error) {
|
|
allow.disabled = false;
|
|
root.append(errorBox(error.message));
|
|
}
|
|
});
|
|
replace(
|
|
root,
|
|
h("h1", {}, "Allow access?"),
|
|
h("div", { class: "approve-app" }, appName),
|
|
h("p", { class: "lede" }, "It wants to scrobble to your account and read your listening history. You can revoke this at any time from Sessions."),
|
|
h("div", { class: "button-row" }, allow, h("a", { class: "button button-quiet", href: "index.html" }, "Don't allow")),
|
|
);
|
|
}
|
|
|
|
function showApproved(appName) {
|
|
replace(
|
|
root,
|
|
h("h1", {}, "Access allowed"),
|
|
h("div", { class: "approve-app" }, appName),
|
|
h("p", { class: "lede" }, "It can now scrobble to your account. Go back to it to finish signing in."),
|
|
h("a", { class: "button button-quiet", href: "sessions.html" }, "View sessions"),
|
|
);
|
|
}
|
|
|
|
function showProblem(error) {
|
|
const expired = error instanceof ApiError && error.status === 404;
|
|
replace(
|
|
root,
|
|
h("h1", {}, expired ? "This link has expired" : "Something went wrong"),
|
|
expired
|
|
? h("p", { class: "lede" }, "Sign-in links last an hour and work once. Start signing in from your player again to get a new one.")
|
|
: errorBox(error.message),
|
|
);
|
|
}
|