CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 14s
CI / federation-interop (push) Successful in 1m7s
CI / test (push) Successful in 3m24s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 6s
New frontend/js/art.js builds a thumbnail that starts as a placeholder and swaps itself for the real cover once (if) it resolves, fetched via the new /api/v1/art/album endpoint with the existing bearer-auth transport and handed to the browser as a blob: object URL (no query-string tokens, no hotlinking). Wired into all four places a track/album appears: the song page's glowing display, the dashboard's "Most played > Albums" list, the dashboard's "Recently played" list, and the full History page - Artists/Tracks rankings are left alone. Also fixes a real reliability gap found during manual testing: Cover Art Archive's existence check (a HEAD request, redirected through archive.org) had no retry at all, unlike the MusicBrainz search next to it, and an occasional slow/flaky response there was enough to fail a lookup outright. It now retries the same way. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
import { api } from "./api.js";
|
|
import { artThumb } from "./art.js";
|
|
import { errorBox, formatDay, formatTime, h, num, replace } from "./dom.js";
|
|
import { signedInPage } from "./layout.js";
|
|
|
|
const PER_PAGE = 50;
|
|
const container = document.getElementById("history");
|
|
const pager = document.getElementById("pager");
|
|
|
|
await signedInPage("history.html");
|
|
const page = Math.max(1, Number.parseInt(new URLSearchParams(location.search).get("page"), 10) || 1);
|
|
|
|
try {
|
|
const result = await api(`/me/recent?page=${page}&limit=${PER_PAGE}`);
|
|
render(result);
|
|
} catch (error) {
|
|
replace(container, errorBox(error.message));
|
|
}
|
|
|
|
function render(result) {
|
|
document.getElementById("history-summary").textContent =
|
|
`${num(result.total)} scrobbles, newest first. Page ${result.page} of ${result.total_pages}.`;
|
|
|
|
if (!result.items.length) {
|
|
replace(container, h("p", { class: "empty" }, "Nothing here yet. Tracks appear once a connected player scrobbles them."));
|
|
return;
|
|
}
|
|
|
|
// Group by local calendar day.
|
|
const days = new Map();
|
|
for (const scrobble of result.items) {
|
|
const key = new Date(scrobble.played_at).toDateString();
|
|
if (!days.has(key)) days.set(key, []);
|
|
days.get(key).push(scrobble);
|
|
}
|
|
replace(
|
|
container,
|
|
[...days.values()].map((scrobbles) => [
|
|
h("h2", { class: "log-day" }, formatDay(scrobbles[0].played_at)),
|
|
h(
|
|
"ol",
|
|
{ class: "log log-clock log-art" },
|
|
scrobbles.map((s) =>
|
|
h(
|
|
"li",
|
|
{},
|
|
artThumb(s.album_artist || s.artist, s.album),
|
|
h("time", { datetime: s.played_at }, formatTime(s.played_at)),
|
|
h(
|
|
"span",
|
|
{},
|
|
h("span", { class: "track" }, s.track),
|
|
h("span", { class: "by" }, ` by ${s.artist}`),
|
|
s.album ? h("span", { class: "by" }, `, from ${s.album}`) : null,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
|
|
replace(
|
|
pager,
|
|
result.page > 1 ? h("a", { class: "button button-quiet", href: `?page=${result.page - 1}` }, "Newer") : h("span"),
|
|
result.page < result.total_pages
|
|
? h("a", { class: "button button-quiet", href: `?page=${result.page + 1}` }, "Older")
|
|
: h("span"),
|
|
);
|
|
}
|