Bug fixes, arr cleanup API-driven scan, shared JS formatters
Bug fixes: - fallback.sh: escape sed metacharacters (\ & |) in state_set values - common.sh: parse PID from lock file content correctly (handles pid:metadata format) - unraid_api_key_renew.sh: fix path depth (../../../) and sync registry key to conf when stale - stop.php: only clear pid/status if process is actually dead — D-state survives SIGKILL - array_started.sh: check ARRAY_START_SCRIPTS empty before printing launch header Arr cleanup: - radarr_cleanup.sh / sonarr_cleanup.sh: fetch root folders from arr API instead of reverse-looking up the path map — handles multi-root-folder setups correctly UI: - varaverk.js: extract shared formatters (_relTime, _fmtBytes, _sz, _uptime, _gb, _tb, _n) - arrs.php / partnership.php: use shared formatters, remove duplicates - arrs.php / fallback.php: show error message on fetch failure instead of silent empty - docker.php: disable rename input during request, restore original value on failure - setup.php: abort controller timeout on detect fetch - partnership.php: remove Re-run Phase 2 button opacity dimming
This commit is contained in:
@@ -1,6 +1,47 @@
|
||||
// Varaverk — shared JS utilities
|
||||
// Page-specific JS lives inline in each page partial.
|
||||
|
||||
// ── Shared formatters ────────────────────────────────────────────────────────
|
||||
const _GB = 1073741824, _MB = 1048576, _TB = 1099511627776;
|
||||
|
||||
// Relative timestamp → "just now" / "5m ago" / "yesterday" / "3d ago"
|
||||
function _relTime(ts) {
|
||||
if (!ts) return '—';
|
||||
const d = Math.floor(Date.now() / 1000) - ts;
|
||||
if (d < 60) return 'just now';
|
||||
if (d < 3600) return Math.floor(d / 60) + 'm ago';
|
||||
if (d < 86400) return Math.floor(d / 3600) + 'h ago';
|
||||
if (d < 172800) return 'yesterday';
|
||||
return Math.floor(d / 86400) + 'd ago';
|
||||
}
|
||||
|
||||
// Bytes → human-readable size (GB / MB / KB)
|
||||
function _fmtBytes(b) {
|
||||
if (!b) return '—';
|
||||
if (b >= _GB) return (b / _GB).toFixed(1) + ' GB';
|
||||
if (b >= _MB) return (b / _MB).toFixed(0) + ' MB';
|
||||
return (b / 1024).toFixed(0) + ' KB';
|
||||
}
|
||||
|
||||
// Bytes → auto-scale TB / GB / MB
|
||||
function _sz(b) {
|
||||
if (!b) return '—';
|
||||
if (b >= _TB) return (b / _TB).toFixed(1) + ' TB';
|
||||
if (b >= _GB) return (b / _GB).toFixed(1) + ' GB';
|
||||
return (b / _MB).toFixed(0) + ' MB';
|
||||
}
|
||||
|
||||
function _gb(b) { return !b ? '—' : (b / _GB).toFixed(1) + ' GB'; }
|
||||
function _tb(b) { return !b ? '—' : (b / _TB).toFixed(2) + ' TB'; }
|
||||
function _n(v) { return v == null ? '—' : Number(v).toLocaleString(); }
|
||||
|
||||
// Seconds → uptime string: "2d 3h 5m" / "3h 5m" / "5m"
|
||||
function _uptime(sec) {
|
||||
if (!sec) return '—';
|
||||
const d = Math.floor(sec / 86400), h = Math.floor((sec % 86400) / 3600), m = Math.floor((sec % 3600) / 60);
|
||||
return d > 0 ? `${d}d ${h}h ${m}m` : h > 0 ? `${h}h ${m}m` : `${m}m`;
|
||||
}
|
||||
|
||||
// Flash a status element briefly then fade
|
||||
function vvFlashStatus(el, msg, ok) {
|
||||
el.textContent = msg;
|
||||
|
||||
Reference in New Issue
Block a user