fix(admin): follow jobs on the Library pages, cap the delete list, honest restore tooltip
Review fixes for owner review 2, phase 3 (R6 Library on the web panel):
- Trash: the worker can end an emptying before the browser has read the
POST's 202, so its jobState arrived while the page did not know the job
yet; Empty then stayed disabled ("being emptied") and no result showed.
The page now keeps the last state of the jobs that ended and looks its
job up there before following it. Any ended job also reloads the list
(an emptying from another tab or the desktop sends no sequenceChanged),
and a Restore answered 404 shows the trash as it is now.
- Sequence: thumbnail, proxy, verify and analysis jobs send no
sequenceChanged, so tiles and the cover stayed placeholders and the
status chips stale. An ended job now schedules one refresh (not pushed
back by the next): the sequence is read again and failed images are
asked for again under a retry address (shared retryImages).
- Library list: Esc, Ctrl+A or unticking every card left the "Select all"
snapshot in place, hiding Select all and stopping the live refresh from
pruning the selection. It is dropped once no selected sequence lies
beyond the loaded rows; Clear filters clears the selection too.
- The sequences' delete dialog lists at most 500 names (blocked ones
first, with their reasons), like the photos' dialog (shared LISTED).
- Admin.Trash.RestoreSequence.Tip promised a SHA-256 check that a sequence
restore never makes (it moves the folder back); it now says so and names
Verify (en, it; no other culture had the key).
- The upload test's name and comments say what it checks: upload.js is
only imported dynamically, not loaded on click.
Tests pin each change in SystemEndpointTests; the pages were also driven
in a browser against a fake API, where the pre-fix modules fail and the
fixed ones pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 78f66082fd85543d619375574c82cc63a233b7a8)
This commit is contained in:
1 parent
66c3662954
commit
13278710a2
8 files changed
+182
-21
No files matched your search
@@ -4,7 +4,7 @@
|
||||
import { t, plural, applyStrings } from "../i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, toast, errorText, confirmDialog, formDialog, markInvalid, emptyState, routeParams, redraw } from "../ui.js";
|
||||
import { icons } from "../icons.js";
|
||||
import { BULK_LIMIT, factsLine, captureText, cameraLabel, statusChips, lazyImage, watchImages, Selection, selectableGrid, chunks, saveFile, sequencesCsv, today, tagList, coverUrl } from "./library/shared.js";
|
||||
import { BULK_LIMIT, factsLine, captureText, cameraLabel, statusChips, lazyImage, watchImages, Selection, selectableGrid, chunks, saveFile, sequencesCsv, today, tagList, coverUrl, listed } from "./library/shared.js";
|
||||
import { renderSequence } from "./library/sequence.js";
|
||||
import { renderTrash } from "./library/trash.js";
|
||||
|
||||
@@ -137,7 +137,15 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
open: (key) => {
|
||||
location.hash = `#/library?id=${encodeURIComponent(key)}`;
|
||||
},
|
||||
onChange: syncSelection,
|
||||
onChange: () => {
|
||||
// "Select all" holds while sequences beyond the loaded rows stay selected; once none does (Esc, Ctrl+A, every card
|
||||
// unticked) the selection is the loaded rows' again: Select all comes back and a refresh drops sequences gone.
|
||||
if (matching) {
|
||||
const loaded = new Set(rows.map((r) => r.id));
|
||||
if ([...selection.ids].every((id) => loaded.has(id))) matching = null;
|
||||
}
|
||||
syncSelection();
|
||||
},
|
||||
});
|
||||
|
||||
function setFilter(name, value) {
|
||||
@@ -481,10 +489,11 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
}
|
||||
const body = [plural("Admin.Library.DeleteBody", going.length, plural("Admin.Dashboard.PhotoCount", plan.photos), formatBytes(plan.bytes)),
|
||||
blocked.length > 0 ? plural("Admin.Library.DeleteBlocked", blocked.length) : ""].filter(Boolean).join(" ");
|
||||
// Those that stay first, with their reasons; the title and the body count them all.
|
||||
const confirmed = await confirmDialog({
|
||||
title: plural("Admin.Library.DeleteTitle", going.length),
|
||||
body,
|
||||
list: [...going.map((i) => titles.get(i.id) ?? i.id), ...blocked.map((i) => t("Admin.Library.BlockedItem", titles.get(i.id) ?? i.id, i.message ?? i.reason))],
|
||||
list: listed([...blocked.map((i) => t("Admin.Library.BlockedItem", titles.get(i.id) ?? i.id, i.message ?? i.reason)), ...going.map((i) => titles.get(i.id) ?? i.id)]),
|
||||
confirm: t("Admin.Library.DeleteConfirm"),
|
||||
confirmTip: t("Admin.Library.DeleteConfirm.Tip"),
|
||||
cancel: t("Admin.Common.Keep"),
|
||||
@@ -522,6 +531,8 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
root.querySelector("#q").value = "";
|
||||
listHash = filters.sort === "newest" ? "#/library" : `#/library?sort=${filters.sort}`;
|
||||
history.replaceState(null, "", listHash);
|
||||
selection.clear();
|
||||
matching = null;
|
||||
load();
|
||||
root.querySelector("#q").focus();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
import { t, plural, applyStrings } from "../../i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, formatDateTime, toast, errorText, confirmDialog, emptyState, escapeReverts, redraw } from "../../ui.js";
|
||||
import { icons } from "../../icons.js";
|
||||
import { captureText, cameraLabel, spanText, statusChips, lazyImage, watchImages, Selection, selectableGrid, tagList, coverUrl } from "./shared.js";
|
||||
import { captureText, cameraLabel, spanText, statusChips, lazyImage, watchImages, retryImages, Selection, selectableGrid, tagList, coverUrl, listed, JOB_ENDED } from "./shared.js";
|
||||
|
||||
const FRAME_PAGE = 500;
|
||||
/** Deleting more photos than this asks for their number to be typed. */
|
||||
const TYPED_ABOVE = 20;
|
||||
/** Names a delete dialog lists; the count in its title says how many there are in all. */
|
||||
const LISTED = 500;
|
||||
/** How long after a job ended the page reads the sequence again; one read covers every job that ended meanwhile. */
|
||||
const AFTER_JOB_MS = 1500;
|
||||
/** FrameFlags bits the viewer and the tiles name. */
|
||||
const FLAGS = [[1, "Missing"], [2, "Corrupt"], [4, "Duplicate"], [8, "Excluded"]];
|
||||
const MAX_TAGS = 50;
|
||||
@@ -22,6 +22,7 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
let renders = [];
|
||||
let generation = 0;
|
||||
let timer = null;
|
||||
let jobTimer = null;
|
||||
/** Set once this page deleted the sequence, or saw it go: its deletion event then says nothing more. */
|
||||
let leaving = false;
|
||||
const selection = new Selection();
|
||||
@@ -343,7 +344,7 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
const confirmed = await confirmDialog({
|
||||
title: plural("Admin.Sequence.DeletePhotosTitle", plan.photos),
|
||||
body: plural("Admin.Sequence.DeletePhotosBody", plan.photos, formatBytes(plan.bytes)),
|
||||
list: names.length > LISTED ? [...names.slice(0, LISTED), "…"] : names,
|
||||
list: listed(names),
|
||||
confirm: t("Admin.Sequence.DeletePhotosConfirm"),
|
||||
confirmTip: t("Admin.Sequence.DeletePhotosConfirm.Tip"),
|
||||
cancel: t("Admin.Common.Keep"),
|
||||
@@ -535,7 +536,24 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
location.hash = back;
|
||||
}
|
||||
|
||||
/**
|
||||
* After a job ended: thumbnail, proxy, verify and analysis jobs send no sequenceChanged, so the facts and status chips
|
||||
* are read again and the cover and photos that had no thumbnail yet are asked for again.
|
||||
*/
|
||||
async function afterJob() {
|
||||
jobTimer = null;
|
||||
if (!root.isConnected || leaving) return;
|
||||
await reload(false);
|
||||
if (root.isConnected && !leaving) retryImages(root);
|
||||
}
|
||||
|
||||
onEvent((e) => {
|
||||
if (e.type === "jobState") {
|
||||
// The event names no sequence: any job that ended may have worked on this one. The timer is not pushed back by the
|
||||
// next one, so a busy queue still refreshes the page every AFTER_JOB_MS.
|
||||
if (JOB_ENDED.has(e.state) && jobTimer === null) jobTimer = setTimeout(afterJob, AFTER_JOB_MS);
|
||||
return;
|
||||
}
|
||||
if (e.type !== "sequenceChanged" || e.sequenceId !== id) return;
|
||||
if (e.change === "deleted") {
|
||||
gone();
|
||||
|
||||
@@ -10,6 +10,17 @@ export const STATUS = { analysed: 1, deep: 2, proxies: 4, thumbs: 8, verified: 1
|
||||
/** Ids one bulk request may name (LibraryEndpoints.MaxBulkIds). */
|
||||
export const BULK_LIMIT = 1000;
|
||||
|
||||
/** Names a delete dialog lists; the count in its title says how many there are in all. */
|
||||
export const LISTED = 500;
|
||||
|
||||
/** The jobState states after which a job does nothing more. */
|
||||
export const JOB_ENDED = new Set(["done", "failed", "cancelled"]);
|
||||
|
||||
/** A dialog's list cut to LISTED lines and "…", so a delete of thousands never builds thousands of nodes. */
|
||||
export function listed(lines) {
|
||||
return lines.length > LISTED ? [...lines.slice(0, LISTED), "…"] : lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* A camera's name as the desktop and the server's facets give it (PathTemplate.CameraName): the make's brand once,
|
||||
* "Canon EOS R5" (Canon + Canon EOS R5), "Nikon Z 8" (NIKON CORPORATION + NIKON Z 8), "SONY ILCE-7M4".
|
||||
@@ -82,6 +93,21 @@ export function watchImages(root) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The images under root that had nothing to show (a thumbnail not built yet) asked for again, once a job that may have
|
||||
* built them ended: under an address the browser has not tried, so its first answer is not reused.
|
||||
*/
|
||||
export function retryImages(root) {
|
||||
root.querySelectorAll("img.failed").forEach((img) => {
|
||||
const url = new URL(img.getAttribute("src"), location.href);
|
||||
url.searchParams.set("retry", String(Date.now()));
|
||||
img.classList.remove("failed");
|
||||
img.setAttribute("data-fallback", "");
|
||||
img.src = url.pathname + url.search;
|
||||
});
|
||||
watchImages(root);
|
||||
}
|
||||
|
||||
/** A sequence's cover thumbnail; its address changes with the cover and the photos, so a browser's copy never shows an old one. */
|
||||
export function coverUrl(s) {
|
||||
return `/api/v1/sequences/${encodeURIComponent(s.id)}/thumb?v=${s.heroFrameId ?? "first"}-${s.framesVersion}`;
|
||||
|
||||
@@ -5,13 +5,23 @@
|
||||
import { t, plural, applyStrings } from "../../i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, formatDateTime, toast, errorText, confirmDialog, emptyState, redraw, fitColumns } from "../../ui.js";
|
||||
import { icons } from "../../icons.js";
|
||||
import { JOB_ENDED } from "./shared.js";
|
||||
|
||||
/** Ended jobs the page remembers (their ids and last states), oldest dropped first. */
|
||||
const ENDED_KEPT = 100;
|
||||
|
||||
export async function renderTrash(root, { api, setMeta, actions, onEvent }, { back }) {
|
||||
let entries = [];
|
||||
let bytes = 0;
|
||||
/** The empty-trash job this page queued, followed until it ends. */
|
||||
let emptyJob = null;
|
||||
/**
|
||||
* The last jobState of jobs that ended while the page was open: the worker can claim the emptying and end it before
|
||||
* the POST that queued it has answered, so the page looks the job up here once it has its id.
|
||||
*/
|
||||
const ended = new Map();
|
||||
let timer = null;
|
||||
let jobTimer = null;
|
||||
|
||||
actions.innerHTML = `
|
||||
<a class="btn" href="${attr(back)}" data-i18n-title="Admin.Trash.Back.Tip">${icons.back}<span data-i18n="Admin.Trash.Back"></span></a>
|
||||
@@ -84,6 +94,8 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
} catch (err) {
|
||||
toast(errorText(err), true);
|
||||
if (button.isConnected) button.disabled = false;
|
||||
// The entry is gone (emptied or restored elsewhere): the list shows the trash as it is now.
|
||||
if (err.status === 404) await load();
|
||||
return;
|
||||
}
|
||||
const lines = [result.kind === "sequence" ? t("Admin.Trash.RestoredSequence", entry.title)
|
||||
@@ -123,8 +135,13 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
if (!confirmed) return;
|
||||
try {
|
||||
const job = await api.post("/api/v1/archive/trash/empty", { names: null, dryRun: false, fingerprint: plan.fingerprint });
|
||||
emptyJob = job.id;
|
||||
toast(t("Admin.Trash.EmptyQueued"));
|
||||
// Its end may have come over the events before this answer did.
|
||||
const end = ended.get(job.id);
|
||||
if (end) emptyEnded(end);
|
||||
else {
|
||||
emptyJob = job.id;
|
||||
toast(t("Admin.Trash.EmptyQueued"));
|
||||
}
|
||||
} catch (err) {
|
||||
// trash_changed: something entered or left the trash since it was measured; it is shown as it is now.
|
||||
toast(errorText(err), true);
|
||||
@@ -134,12 +151,28 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
}
|
||||
}
|
||||
|
||||
/** The emptying this page queued ended: its toast; the caller shows the trash again. */
|
||||
function emptyEnded(e) {
|
||||
emptyJob = null;
|
||||
if (e.state === "done") toast(t("Admin.Trash.Emptied"));
|
||||
else toast(e.error || t("Admin.Trash.EmptyFailed"), true);
|
||||
}
|
||||
|
||||
onEvent((e) => {
|
||||
if (e.type === "jobState" && e.jobId === emptyJob && (e.state === "done" || e.state === "failed" || e.state === "cancelled")) {
|
||||
emptyJob = null;
|
||||
if (e.state === "done") toast(t("Admin.Trash.Emptied"));
|
||||
else toast(e.error || t("Admin.Trash.EmptyFailed"), true);
|
||||
load();
|
||||
if (e.type === "jobState" && JOB_ENDED.has(e.state)) {
|
||||
ended.set(e.jobId, e);
|
||||
if (ended.size > ENDED_KEPT) ended.delete(ended.keys().next().value);
|
||||
if (e.jobId === emptyJob) {
|
||||
emptyEnded(e);
|
||||
load();
|
||||
} else if (jobTimer === null) {
|
||||
// An emptying started elsewhere (another tab, the desktop) sends no sequenceChanged. The timer is not pushed
|
||||
// back by the next job, so a busy queue still shows the trash again.
|
||||
jobTimer = setTimeout(() => {
|
||||
jobTimer = null;
|
||||
if (root.isConnected) load();
|
||||
}, 1500);
|
||||
}
|
||||
} else if (e.type === "sequenceChanged") {
|
||||
// A deletion or a restore elsewhere changes what the trash holds.
|
||||
clearTimeout(timer);
|
||||
|
||||
Reference in new issue
Block a user