Files
Chronos/src/Chronos.Server/Admin/web/pages/archive.js
T
Alby96andClaude Opus 5.5 d560b41b81 feat(server): show the Unraid array's free space and check the archive volume before filing uploads
On Unraid the archive is a user share (FUSE shfs), which reports the share's
primary storage, often the cache, while the mover sends the photos to the
array: the admin panel showed the cache's free space (owner review 2, R2).

- New option SpacePath (server.json) / CHRONOS_SPACE_PATH: the admin panel
  shows that folder's volume; empty, or a folder that cannot be measured, falls
  back to the archive's volume (one warning, at start, not per request).
- VolumeSpace measures folders (DriveInfo; the path root on Windows) and reads
  the filesystem type and mount from /proc/self/mountinfo on Linux (longest
  mount point on segment boundaries, octal escapes, optional fields, the top of
  stacked mounts), since DriveFormat calls an shfs share only "fuse". It is an
  injectable service, so tests simulate a full volume; the /data checks use it.
- ArchiveStatsDto keeps FreeBytes/CapacityBytes for the shown volume and gains
  optional trailing members: the write volume's figures (when a space path is
  in use and they differ), the filesystem type and UsesSpacePath.
- Admin panel (dashboard and archive): a tooltip on the storage figures names
  the volume and its filesystem and, on an shfs share without a space path,
  says they are the primary storage and to map the array view to /space; a
  "Write volume" line shows the archive's own volume when it differs.
- Completing an upload, a render upload or a render node's result checks the
  archive volume for its size plus the 64 MiB reserve before the staging copy
  and answers 507 insufficient_storage, the upload still receiving.
- Diagnostics list the archive and space volumes with filesystem and mount.
- Unraid template: optional read-only "Array view" /space (default
  /mnt/user0/Timelapse) and "Space path" CHRONOS_SPACE_PATH=/space; compose and
  the releases README describe the same as an option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 21:58:27 +01:00

122 lines
8.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Archive (BRIEF §14.8): naming templates, proxy policy, scan/rebuild/verify/maintenance, statistics.
import { t, plural, applyStrings } from "../i18n.js";
import { escapeHtml, attr, formatBytes, formatNumber, bar, storageTip, writeVolumeLine, columns, toast, errorText, emptyState, markInvalid, clearInvalid, invalidText, escapeReverts } from "../ui.js";
const PROXY_SIZES = [-1, 1280, 1920, 2560, 3840, 0];
const ACTIONS = ["scan", "rebuild", "verify", "maintenance"];
export async function render(root, { api, setMeta }) {
let settings;
let stats;
try {
[settings, stats] = await Promise.all([api.get("/api/v1/archive/settings"), api.get("/api/v1/archive/stats")]);
} catch (err) {
root.innerHTML = `<div class="panel empty">${escapeHtml(errorText(err))}</div>`;
return;
}
setMeta(settings.rootPath, { ltr: true });
// The space volume's figures (the space path when the server has one), the write volume apart when it differs.
const used = stats.capacityBytes > 0 ? (stats.capacityBytes - stats.freeBytes) / stats.capacityBytes : 0;
const spaceTip = attr(storageTip(stats));
const sizes = PROXY_SIZES.includes(settings.proxyLongEdge) ? PROXY_SIZES : [settings.proxyLongEdge, ...PROXY_SIZES];
const proxyOptions = sizes.map((size) => `<option value="${size}" ${size === settings.proxyLongEdge ? "selected" : ""}>${escapeHtml(proxyLabel(size))}</option>`).join("");
const statsTable = (rows, labelId) => rows.length === 0 ? "" : `<div class="table compact stats" role="table" aria-labelledby="${labelId}"><div role="rowgroup">${rows.map((r) =>
`<div class="row" role="row"><span class="ellipsis" role="cell" dir="auto">${escapeHtml(r.label)}</span><span class="num end" role="cell">${formatNumber(r.count)}</span><span class="num end" role="cell">${escapeHtml(formatBytes(r.bytes))}</span></div>`).join("")}</div></div>`;
const scanButton = `<button class="btn small" data-action="scan" data-i18n="Admin.Archive.Scan" data-i18n-title="Admin.Archive.Scan.Tip"></button>`;
root.innerHTML = `
<div class="tiles">
<section class="panel tile" aria-labelledby="tile-sequences"><h2 class="label" id="tile-sequences" data-i18n="Admin.Archive.Sequences"></h2><span class="value num">${formatNumber(stats.sequences)}</span>
<span class="sub">${escapeHtml(`${plural("Admin.Dashboard.PhotoCount", stats.photos)} · ${plural("Admin.Dashboard.CameraCount", stats.cameras)}`)}</span></section>
<section class="panel tile" aria-labelledby="tile-originals"><h2 class="label" id="tile-originals" data-i18n="Admin.Archive.Originals"></h2><span class="value">${escapeHtml(formatBytes(stats.bytes))}</span>
<span class="sub num">${escapeHtml(stats.firstYear ? `${stats.firstYear}–${stats.lastYear}` : "—")}</span></section>
<section class="panel tile" aria-labelledby="tile-storage"><h2 class="label" id="tile-storage" data-i18n="Admin.Dashboard.Storage"></h2><span class="value" title="${spaceTip}">${escapeHtml(formatBytes(stats.freeBytes))}<small data-i18n="Admin.Archive.FreeShort"></small></span>
${bar(used)}<span class="sub" title="${spaceTip}">${escapeHtml(t("Admin.Dashboard.Of", formatBytes(stats.capacityBytes)))}</span>${writeVolumeLine(stats)}</section>
<section class="panel tile" aria-labelledby="tile-health"><h2 class="label" id="tile-health" data-i18n="Admin.Archive.Health"></h2><span class="value num">${formatNumber(stats.unverifiedSequences)}<small>${escapeHtml(plural("Admin.Archive.UnverifiedUnit", stats.unverifiedSequences))}</small></span>
<span class="sub">${escapeHtml(plural("Admin.Dashboard.WithoutProxies", stats.sequencesWithoutProxies))}</span></section>
</div>
<div class="grid two">
<form class="panel form settings-form" novalidate aria-labelledby="layout-title">
<h2 id="layout-title" data-i18n="Admin.Archive.Layout"></h2>
<label class="field"><span data-i18n="Admin.Archive.Name"></span><input class="input" name="name" dir="auto" value="${attr(settings.name)}" data-i18n-title="Admin.Archive.Name.Tip"></label>
<label class="field"><span data-i18n="Admin.Archive.FolderTemplate"></span><input class="input mono" name="folderTemplate" dir="ltr" spellcheck="false" value="${attr(settings.folderTemplate)}" data-i18n-title="Admin.Archive.FolderTemplate.Tip"></label>
<label class="field"><span data-i18n="Admin.Archive.FileTemplate"></span><input class="input mono" name="fileTemplate" dir="ltr" spellcheck="false" value="${attr(settings.fileTemplate)}" data-i18n-title="Admin.Archive.FileTemplate.Tip"></label>
<label class="field"><span data-i18n="Admin.Archive.Proxies"></span><select class="input" name="proxyLongEdge" data-i18n-title="Admin.Archive.Proxies.Tip">${proxyOptions}</select></label>
<div class="buttons"><button class="btn primary" type="submit" data-i18n="Admin.Common.Save" data-i18n-title="Admin.Common.Save.Tip"></button></div>
</form>
<section class="panel" aria-labelledby="maintenance-title">
<h2 id="maintenance-title" data-i18n="Admin.Archive.Maintenance"></h2>
<div class="button-row">${ACTIONS.map((a) => `<button class="btn" data-action="${a}" data-i18n="Admin.Archive.${cap(a)}" data-i18n-title="Admin.Archive.${cap(a)}.Tip"></button>`).join("")}</div>
<h2 id="cameras-title" data-i18n="Admin.Archive.ByCamera"></h2>
${statsTable(stats.byCamera.slice(0, 8).map((c) => ({ label: c.key || "—", count: c.count, bytes: c.bytes })), "cameras-title")
|| `<p class="muted" data-i18n="Admin.Dashboard.NoData"></p>`}
</section>
</div>
<div class="grid two charts">
<section class="panel" aria-labelledby="years-title"><h2 id="years-title" data-i18n="Admin.Dashboard.ByYear"></h2>
${stats.byYear.length === 0 ? emptyState("Admin.Dashboard.NoData", scanButton)
: columns(stats.byYear.map((y) => ({ label: y.key, value: y.bytes, title: `${y.key} · ${formatBytes(y.bytes)}` })),
{ label: t("Admin.Dashboard.ByYear"), valueLabel: (i) => formatBytes(i.value) })}</section>
<section class="panel" aria-labelledby="formats-title"><h2 id="formats-title" data-i18n="Admin.Archive.ByFormat"></h2>
${statsTable(stats.byFormat.map((f) => ({ label: f.key.toUpperCase(), count: f.count, bytes: f.bytes })), "formats-title")
|| emptyState("Admin.Dashboard.NoData", scanButton)}</section>
</div>`;
applyStrings(root);
const form = root.querySelector("form");
escapeReverts(form);
form.addEventListener("submit", async (e) => {
e.preventDefault();
form.querySelectorAll("[aria-invalid]").forEach(clearInvalid);
const data = new FormData(form);
try {
settings = await api.put("/api/v1/archive/settings", {
...settings,
name: String(data.get("name")).trim(),
folderTemplate: String(data.get("folderTemplate")),
fileTemplate: String(data.get("fileTemplate")),
proxyLongEdge: Number(data.get("proxyLongEdge")),
});
// Esc now reverts to what was saved.
form.querySelectorAll("input").forEach((input) => {
input.defaultValue = input.value;
});
form.querySelectorAll("option").forEach((option) => {
option.defaultSelected = option.selected;
});
toast(t("Admin.Common.Saved"));
} catch (err) {
// Errors name the field in details; the field gets the error border and the message as its tooltip.
const field = err.details && form.elements[err.details];
const message = field ? invalidText(field) : errorText(err);
if (field) {
markInvalid(field, message);
field.focus();
}
toast(message, true);
}
});
root.querySelectorAll("[data-action]").forEach((button) => button.addEventListener("click", async () => {
button.disabled = true;
try {
await api.post(`/api/v1/archive/${button.dataset.action}`);
toast(t("Admin.Archive.Queued"));
} catch (err) {
toast(errorText(err), true);
} finally {
button.disabled = false;
button.focus();
}
}));
}
function proxyLabel(size) {
if (size === -1) return t("Admin.Archive.ProxiesOff");
if (size === 0) return t("Admin.Archive.ProxiesFull");
return t("Admin.Archive.ProxiesEdge", size);
}
function cap(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}