Files
Chronos/src/Chronos.Server/Admin/web/audit.js
T
Alby96andClaude Opus 5.5 9aa818ed47
CI / Build and test (push) Successful in 7m25s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
CI / PostgreSQL 16 integration (push) Successful in 5m20s
CI / PostgreSQL 17 integration (push) Successful in 5m22s
CI / Docker image (push) Successful in 50s
Release / Build, test and publish (push) Successful in 12m1s
Release / Server image (push) Successful in 1m26s
feat: owner review 2 phase 3: Library on the web panel, photo trash and web upload (#11)
- Web panel Library: browse, view, delete sequences and photos, mass operations (analyse, proxies, thumbnails, verify, retag, delete, CSV). It never edits the video.
- Photo trash with tombstones (migration 0008): crash-safe delete and restore, hash-checked restore with reasons, and emptying only by an explicit fingerprinted job. Sync and uploads keep deleted photos deleted; an explicit "Upload again" brings one back.
- Upload from the web panel: in-house SHA-256 in a worker with a fail-closed self-test, capture time from EXIF, chunked, resumable; no folders.
- Desktop trash dialog with photo entries and Empty.
- Admin files are revalidated (no-cache + ETag).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-27 15:08:39 +01:00

108 lines
4.6 KiB
JavaScript

// Audit entries as the dashboard and the Logs page show them: server codes (actions, job kinds, roles, changed
// fields, schedule recurrences) in words, system schedules by their names in the panel's language; other names, titles
// and templates stay as recorded.
import { t, has, plural } from "./i18n.js";
import { formatBytes } from "./ui.js";
import { kindLabel, pascal } from "./jobs.js";
import { actionLabel as scheduleAction, outcomeLabel, scheduleName, recurrenceText, parseRecurrence } from "./schedules.js";
const SYSTEM = "system:";
export function actionLabel(action) {
const key = `Admin.Logs.Action.${pascal(action)}`;
return has(key) ? t(key) : action;
}
/** One sentence per entry, e.g. "alberto signed in · Chronos 0.1.0" (unknown actions show their code). */
export function activityText(entry) {
const key = `Admin.Activity.${pascal(entry.action)}`;
return has(key) ? t(key, entry.username ?? "—", detailText(entry)) : `${entry.username ?? ""} ${entry.action}`;
}
/** The details of an entry: "verify" → "Verify", "lucia · editor" → "lucia · Editor", "role=viewer, quota=0" → "role Viewer, no quota". */
export function detailText(entry) {
const details = entry.details ?? "";
if (!details) return "";
switch (entry.action) {
case "job_created": {
const [kind, ...label] = details.split(" · ");
return [kindLabel(kind), ...label].join(" · ");
}
case "user_created": {
const [name, role] = splitLast(details);
return role === undefined ? details : `${name} · ${roleLabel(role)}`;
}
case "user_deleted": {
const [name, count] = splitLast(details);
return /^\d+$/.test(count ?? "") ? `${name} · ${plural("Admin.Logs.Reassigned", Number(count))}` : details;
}
case "user_updated":
case "sequence_updated":
return details.split(", ").map(changeLabel).join(", ");
case "schedule_run": {
// "[system:<key> · ]name · outcome"
const parts = details.split(" · ");
if (parts.length < 2) return details;
const outcome = parts.pop();
return `${scheduleNameIn(parts)} · ${outcomeLabel(outcome)}`;
}
case "schedule_created":
case "schedule_updated":
case "schedule_deleted":
case "schedule_reset": {
// "[system:<key> · ]name · action · recurrence[ · off]", read from the end: a name may hold the separator.
const parts = details.split(" · ");
const off = parts.at(-1) === "off";
if (off) parts.pop();
if (parts.length < 3) return details;
const code = parts.pop();
const action = parts.pop();
const recurrence = parseRecurrence(code);
const shown = [scheduleNameIn(parts), scheduleAction(action), recurrence ? recurrenceText(recurrence) : code];
return (off ? [...shown, t("Admin.Schedules.Off")] : shown).join(" · ");
}
// Owner review 2, R6: "3 · photos-<entry>", "<entry> · Harbour sunset", "2 · 1048576 · <entries>".
case "frames_deleted": {
const [count] = details.split(" · ");
return /^\d+$/.test(count) ? plural("Admin.Dashboard.PhotoCount", Number(count)) : details;
}
case "trash_restored": {
const [, ...title] = details.split(" · ");
return title.length > 0 ? title.join(" · ") : details;
}
case "trash_empty_requested": {
const [count, size] = details.split(" · ");
return /^\d+$/.test(count) && /^\d+$/.test(size ?? "") ? `${plural("Admin.Trash.EntryCount", Number(count))} · ${formatBytes(Number(size))}` : details;
}
default:
return details;
}
}
export function roleLabel(role) {
const key = `Admin.Role.${pascal(role)}`;
return has(key) ? t(key) : role;
}
function changeLabel(change) {
const [field, value] = change.split("=");
if (field === "role") return t("Admin.Logs.Field.Role", roleLabel(value ?? ""));
if (field === "quota") return Number(value) > 0 ? t("Admin.Logs.Field.Quota", formatBytes(Number(value))) : t("Admin.Logs.Field.NoQuota");
const key = `Admin.Logs.Field.${pascal(field)}`;
return has(key) ? t(key) : change;
}
/**
* A schedule's name from the leading parts of audit details: after "system:<key>" a system schedule's in the panel's
* language, as the Scheduled tab names it; else (a user's, or one recorded before keys were) as recorded.
*/
function scheduleNameIn(parts) {
const systemKey = parts.length > 1 && parts[0].startsWith(SYSTEM) ? parts[0].slice(SYSTEM.length) : null;
return scheduleName({ systemKey, name: (systemKey ? parts.slice(1) : parts).join(" · ") });
}
function splitLast(details) {
const at = details.lastIndexOf(" · ");
return at < 0 ? [details] : [details.slice(0, at), details.slice(at + 3)];
}