feat(admin): purge-archived endpoint with an archived-items banner

Bulk escape hatch for archived rows (files missing from disk for 2+
scans) so a mass external deletion never has to wait out the retention
window or be clicked away row by row:

- POST /api/media-items/purge-archived (admin only) hard-deletes all
  archived items and returns the purged count; reading history goes with
  the rows, so the call is confirmed in the UI first.
- The library admin page shows an 'Archived items: N' card (only when
  non-zero) with a Purge Archived Now button that calls the endpoint,
  toasts the result, and reloads.
- Frontend admin JS exposes window.purgeArchivedItems following the
  existing localStorage-bearer-token pattern.
This commit is contained in:
John O'Keefe
2026-09-12 17:50:24 -04:00
parent 14445a7c3f
commit cd119a74da
6 changed files with 388 additions and 277 deletions
+40
View File
@@ -249,6 +249,46 @@ function stopScanStatusPolling(): void {
}
}
// Purge all archived items (files missing from disk for 2+ scans). Exposed on
// window for the library admin page's inline button; reading history is
// deleted with the rows, so a confirm dialog guards it.
async function purgeArchivedItems(): Promise<void> {
const token = localStorage.getItem("token");
if (!token) return;
if (
!window.confirm(
"Permanently delete all archived items? Their reading progress, notes, and highlights will be lost.",
)
) {
return;
}
try {
const resp = await fetch("/api/media-items/purge-archived", {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
});
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
throw new Error(err.error || "Failed to purge archived items");
}
const data = await resp.json();
showToast(
`Purged ${data.purged} archived item${data.purged === 1 ? "" : "s"}`,
"success",
);
setTimeout(() => window.location.reload(), 700);
} catch (e) {
showToast(
e instanceof Error ? e.message : "Failed to purge archived items",
"error",
);
}
}
(window as any).purgeArchivedItems = purgeArchivedItems;
export {
hideScanProgress,
loadWatchStatus,