Merge feat/debug-uptime-timer
@@ -101,6 +101,7 @@
101
101
- GET /api/admin/debug/stream-stats - Also reports host/process memory ({total, free, used, usedPercent, processRssBytes, processHeapUsedBytes}) so streaming lag can be correlated with RAM pressure.
102
102
- GET /api/admin/debug/stream-stats - Also reports the subtitle debug cache directory metadata so admins can open the local subtitle log folder from the debug dashboard.
103
103
- GET /api/admin/debug/stream-stats - Also reports server maintenance diagnostics: auth/share row counts, auth/share cleanup loop snapshots, and scheduled-restart runtime state.
104
- GET /api/admin/debug/stream-stats - Maintenance diagnostics now include process uptime fields (`uptimeMs`, `startedAt`) so the debug dashboard can show a live uptime timer.
104
105
105
106
## server/routes/files.js
106
107
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
@@ -252,6 +253,7 @@
252
253
- onBrowserPopState(event) - When history reaches browse index 0, shows: "Do you want to close the application and return to the previous webpage?" and on Yes runs normal browser back navigation.
253
254
- renderDebugDashboardData(data) - Renders the debug dashboard panels, including the subtitle debug cache folder summary and open-folder action.
254
255
- renderDebugDashboardData(data) - Also renders server-maintenance diagnostics (auth/share row totals, maintenance loop last-run telemetry, scheduled restart status/timing).
256
- renderDebugDashboardData(data) - Server maintenance summary now includes a live "Server uptime" timer row above scheduled restart, updated every second while the debug modal is open.
255
257
- performLogout() - Explicit logout path that revokes server session and clears local session state.
256
258
- initAuth() - Restores prior session when valid and auto-logins without credential prompt.
257
259
- showConfirm(title, message, { html, okLabel, modalClass }) - In-page confirm dialog; returns Promise<boolean>. `html=true` renders message as innerHTML (caller must escape user data), `okLabel` overrides the OK button text, and `modalClass` temporarily widens/restyles the dialog for rich content.
@@ -101,6 +101,7 @@101
- GET /api/admin/debug/stream-stats - Also reports host/process memory ({total, free, used, usedPercent, processRssBytes, processHeapUsedBytes}) so streaming lag can be correlated with RAM pressure.
101
- GET /api/admin/debug/stream-stats - Also reports host/process memory ({total, free, used, usedPercent, processRssBytes, processHeapUsedBytes}) so streaming lag can be correlated with RAM pressure.
102
- GET /api/admin/debug/stream-stats - Also reports the subtitle debug cache directory metadata so admins can open the local subtitle log folder from the debug dashboard.
102
- GET /api/admin/debug/stream-stats - Also reports the subtitle debug cache directory metadata so admins can open the local subtitle log folder from the debug dashboard.
103
- GET /api/admin/debug/stream-stats - Also reports server maintenance diagnostics: auth/share row counts, auth/share cleanup loop snapshots, and scheduled-restart runtime state.
103
- GET /api/admin/debug/stream-stats - Also reports server maintenance diagnostics: auth/share row counts, auth/share cleanup loop snapshots, and scheduled-restart runtime state.
104
- GET /api/admin/debug/stream-stats - Maintenance diagnostics now include process uptime fields (`uptimeMs`, `startedAt`) so the debug dashboard can show a live uptime timer.
104
105
105
## server/routes/files.js
106
## server/routes/files.js
106
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
107
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
@@ -252,6 +253,7 @@252
- onBrowserPopState(event) - When history reaches browse index 0, shows: "Do you want to close the application and return to the previous webpage?" and on Yes runs normal browser back navigation.
253
- onBrowserPopState(event) - When history reaches browse index 0, shows: "Do you want to close the application and return to the previous webpage?" and on Yes runs normal browser back navigation.
253
- renderDebugDashboardData(data) - Renders the debug dashboard panels, including the subtitle debug cache folder summary and open-folder action.
254
- renderDebugDashboardData(data) - Renders the debug dashboard panels, including the subtitle debug cache folder summary and open-folder action.
254
- renderDebugDashboardData(data) - Also renders server-maintenance diagnostics (auth/share row totals, maintenance loop last-run telemetry, scheduled restart status/timing).
255
- renderDebugDashboardData(data) - Also renders server-maintenance diagnostics (auth/share row totals, maintenance loop last-run telemetry, scheduled restart status/timing).
256
- renderDebugDashboardData(data) - Server maintenance summary now includes a live "Server uptime" timer row above scheduled restart, updated every second while the debug modal is open.
255
- performLogout() - Explicit logout path that revokes server session and clears local session state.
257
- performLogout() - Explicit logout path that revokes server session and clears local session state.
256
- initAuth() - Restores prior session when valid and auto-logins without credential prompt.
258
- initAuth() - Restores prior session when valid and auto-logins without credential prompt.
257
- showConfirm(title, message, { html, okLabel, modalClass }) - In-page confirm dialog; returns Promise<boolean>. `html=true` renders message as innerHTML (caller must escape user data), `okLabel` overrides the OK button text, and `modalClass` temporarily widens/restyles the dialog for rich content.
259
- showConfirm(title, message, { html, okLabel, modalClass }) - In-page confirm dialog; returns Promise<boolean>. `html=true` renders message as innerHTML (caller must escape user data), `okLabel` overrides the OK button text, and `modalClass` temporarily widens/restyles the dialog for rich content.
@@ -5442,6 +5442,7 @@ async function deleteItem (item)
5442
5442
5443
5443
let _adminUpdateStatus = null;
5444
5444
let _debugRefreshTimer = null;
5445
let _debugUptimeTimer = null;
5445
5446
let _debugLatestData = null;
5446
5447
let _adminConfigCache = null;
5447
5448
@@ -5496,6 +5497,45 @@ function formatTimestamp (ms)
5496
5497
}
5497
5498
}
5498
5499
5500
function formatElapsedDuration (ms)
5501
{
5502
const totalMs = Number(ms || 0);
5503
if (!Number.isFinite(totalMs) || totalMs < 0) return '—';
5504
5505
const totalSeconds = Math.floor(totalMs / 1000);
5506
const days = Math.floor(totalSeconds / 86400);
5507
const hours = Math.floor((totalSeconds % 86400) / 3600);
5508
const minutes = Math.floor((totalSeconds % 3600) / 60);
5509
const seconds = totalSeconds % 60;
5510
5511
const hms = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
5512
if (days <= 0) return hms;
5513
return `${days}d ${hms}`;
5514
}
5515
5516
function getDebugUptimeMsNow ()
5517
{
5518
const data = _debugLatestData || {};
5519
const maintenance = data.maintenance || {};
5520
const baseUptimeMs = Number(maintenance.uptimeMs || 0);
5521
if (!Number.isFinite(baseUptimeMs) || baseUptimeMs < 0) return null;
5522
5523
const generatedAt = Number(data.generatedAt || 0);
5524
const elapsedSinceSnapshotMs = Number.isFinite(generatedAt) && generatedAt > 0
5525
? Math.max(0, Date.now() - generatedAt)
5526
: 0;
5527
return baseUptimeMs + elapsedSinceSnapshotMs;
5528
}
5529
5530
function renderDebugUptimeTimer ()
5531
{
5532
const valueEl = document.getElementById('debug-maintenance-uptime-value');
5533
if (!valueEl) return;
5534
5535
const uptimeMs = getDebugUptimeMsNow();
5536
valueEl.textContent = uptimeMs === null ? '—' : formatElapsedDuration(uptimeMs);
5537
}
5538
5499
5539
function renderDebugTable (containerId, columns, rows)
5500
5540
{
5501
5541
const container = document.getElementById(containerId);
@@ -5574,10 +5614,13 @@ function renderDebugDashboardData (data)
5574
5614
['Share tokens (expired)', String(rows.shareTokensExpired || 0)],
5575
5615
['Auth cleanup last run', formatTimestamp(authCleanup.lastRunAt)],
5576
5616
['Share cleanup last run', formatTimestamp(shareMaintenance.lastRunAt)],
5617
['Server uptime', `<span id="debug-maintenance-uptime-value">${escapeHtml(formatElapsedDuration(getDebugUptimeMsNow()))}</span>`],
5577
5618
['Scheduled restart', scheduledLine],
5578
5619
['Next scheduled restart', formatTimestamp(scheduledRestart.nextDueAt)],
5579
5620
['Pending since', formatTimestamp(scheduledRestart.pendingSinceAt)],
5580
].map(([k, v]) => `<div class="debug-summary-item"><span class="k">${escapeHtml(k)}</span><span class="v">${escapeHtml(v)}</span></div>`).join('');
5621
].map(([k, v]) => `<div class="debug-summary-item"><span class="k">${escapeHtml(k)}</span><span class="v">${k === 'Server uptime' ? v : escapeHtml(v)}</span></div>`).join('');
5622
5623
renderDebugUptimeTimer();
5581
5624
}
5582
5625
5583
5626
renderDebugTable(
@@ -5806,6 +5849,12 @@ async function openDebugModal ()
5806
5849
{
5807
5850
void refreshDebugDashboard();
5808
5851
}, 5000);
5852
5853
if (_debugUptimeTimer) clearInterval(_debugUptimeTimer);
5854
_debugUptimeTimer = setInterval(() =>
5855
{
5856
renderDebugUptimeTimer();
5857
}, 1000);
5809
5858
}
5810
5859
5811
5860
function closeDebugModal ()
@@ -5817,6 +5866,11 @@ function closeDebugModal ()
5817
5866
clearInterval(_debugRefreshTimer);
5818
5867
_debugRefreshTimer = null;
5819
5868
}
5869
if (_debugUptimeTimer)
5870
{
5871
clearInterval(_debugUptimeTimer);
5872
_debugUptimeTimer = null;
5873
}
5820
5874
}
5821
5875
5822
5876
function animateBadgeToTarget (targetEl)
@@ -5442,6 +5442,7 @@ async function deleteItem (item)5442
5442
5443
let _adminUpdateStatus = null;5443
let _adminUpdateStatus = null;5444
let _debugRefreshTimer = null;5444
let _debugRefreshTimer = null;5445
let _debugUptimeTimer = null;5445
let _debugLatestData = null;5446
let _debugLatestData = null;5446
let _adminConfigCache = null;5447
let _adminConfigCache = null;5447
5448
@@ -5496,6 +5497,45 @@ function formatTimestamp (ms)5496
}5497
}5497
}5498
}5498
5499
5500
function formatElapsedDuration (ms)5501
{5502
const totalMs = Number(ms || 0);5503
if (!Number.isFinite(totalMs) || totalMs < 0) return '—';5504
5505
const totalSeconds = Math.floor(totalMs / 1000);5506
const days = Math.floor(totalSeconds / 86400);5507
const hours = Math.floor((totalSeconds % 86400) / 3600);5508
const minutes = Math.floor((totalSeconds % 3600) / 60);5509
const seconds = totalSeconds % 60;5510
5511
const hms = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;5512
if (days <= 0) return hms;5513
return `${days}d ${hms}`;5514
}5515
5516
function getDebugUptimeMsNow ()5517
{5518
const data = _debugLatestData || {};5519
const maintenance = data.maintenance || {};5520
const baseUptimeMs = Number(maintenance.uptimeMs || 0);5521
if (!Number.isFinite(baseUptimeMs) || baseUptimeMs < 0) return null;5522
5523
const generatedAt = Number(data.generatedAt || 0);5524
const elapsedSinceSnapshotMs = Number.isFinite(generatedAt) && generatedAt > 05525
? Math.max(0, Date.now() - generatedAt)5526
: 0;5527
return baseUptimeMs + elapsedSinceSnapshotMs;5528
}5529
5530
function renderDebugUptimeTimer ()5531
{5532
const valueEl = document.getElementById('debug-maintenance-uptime-value');5533
if (!valueEl) return;5534
5535
const uptimeMs = getDebugUptimeMsNow();5536
valueEl.textContent = uptimeMs === null ? '—' : formatElapsedDuration(uptimeMs);5537
}5538
5499
function renderDebugTable (containerId, columns, rows)5539
function renderDebugTable (containerId, columns, rows)5500
{5540
{5501
const container = document.getElementById(containerId);5541
const container = document.getElementById(containerId);@@ -5574,10 +5614,13 @@ function renderDebugDashboardData (data)5574
['Share tokens (expired)', String(rows.shareTokensExpired || 0)],5614
['Share tokens (expired)', String(rows.shareTokensExpired || 0)],5575
['Auth cleanup last run', formatTimestamp(authCleanup.lastRunAt)],5615
['Auth cleanup last run', formatTimestamp(authCleanup.lastRunAt)],5576
['Share cleanup last run', formatTimestamp(shareMaintenance.lastRunAt)],5616
['Share cleanup last run', formatTimestamp(shareMaintenance.lastRunAt)],5617
['Server uptime', `<span id="debug-maintenance-uptime-value">${escapeHtml(formatElapsedDuration(getDebugUptimeMsNow()))}</span>`],5577
['Scheduled restart', scheduledLine],5618
['Scheduled restart', scheduledLine],5578
['Next scheduled restart', formatTimestamp(scheduledRestart.nextDueAt)],5619
['Next scheduled restart', formatTimestamp(scheduledRestart.nextDueAt)],5579
['Pending since', formatTimestamp(scheduledRestart.pendingSinceAt)],5620
['Pending since', formatTimestamp(scheduledRestart.pendingSinceAt)],5580
].map(([k, v]) => `<div class="debug-summary-item"><span class="k">${escapeHtml(k)}</span><span class="v">${escapeHtml(v)}</span></div>`).join('');5621
].map(([k, v]) => `<div class="debug-summary-item"><span class="k">${escapeHtml(k)}</span><span class="v">${k === 'Server uptime' ? v : escapeHtml(v)}</span></div>`).join('');5622
5623
renderDebugUptimeTimer();5581
}5624
}5582
5625
5583
renderDebugTable(5626
renderDebugTable(@@ -5806,6 +5849,12 @@ async function openDebugModal ()5806
{5849
{5807
void refreshDebugDashboard();5850
void refreshDebugDashboard();5808
}, 5000);5851
}, 5000);5852
5853
if (_debugUptimeTimer) clearInterval(_debugUptimeTimer);5854
_debugUptimeTimer = setInterval(() =>5855
{5856
renderDebugUptimeTimer();5857
}, 1000);5809
}5858
}5810
5859
5811
function closeDebugModal ()5860
function closeDebugModal ()@@ -5817,6 +5866,11 @@ function closeDebugModal ()5817
clearInterval(_debugRefreshTimer);5866
clearInterval(_debugRefreshTimer);5818
_debugRefreshTimer = null;5867
_debugRefreshTimer = null;5819
}5868
}5869
if (_debugUptimeTimer)5870
{5871
clearInterval(_debugUptimeTimer);5872
_debugUptimeTimer = null;5873
}5820
}5874
}5821
5875
5822
function animateBadgeToTarget (targetEl)5876
function animateBadgeToTarget (targetEl)@@ -244,7 +244,8 @@
244
244
<input id="admin-scheduled-restart-time" type="time" step="60" />
245
245
</label>
246
246
</div>
247
<p id="admin-scheduled-restart-help" class="muted">When the scheduled time is reached, restart waits until there have been no logged-in clients for at least one hour.</p>
247
<p id="admin-scheduled-restart-help" class="muted">When the scheduled time is reached, restart waits until
248
there have been no logged-in clients for at least one hour.</p>
248
249
<button id="admin-save-scheduled-restart" class="primary">Save scheduled restart</button>
249
250
</div>
250
251
<button id="admin-shutdown-btn" class="danger">Shut down server</button>
@@ -244,7 +244,8 @@244
<input id="admin-scheduled-restart-time" type="time" step="60" />244
<input id="admin-scheduled-restart-time" type="time" step="60" />245
</label>245
</label>246
</div>246
</div>247
<p id="admin-scheduled-restart-help" class="muted">When the scheduled time is reached, restart waits until there have been no logged-in clients for at least one hour.</p>247
<p id="admin-scheduled-restart-help" class="muted">When the scheduled time is reached, restart waits until248
there have been no logged-in clients for at least one hour.</p>248
<button id="admin-save-scheduled-restart" class="primary">Save scheduled restart</button>249
<button id="admin-save-scheduled-restart" class="primary">Save scheduled restart</button>249
</div>250
</div>250
<button id="admin-shutdown-btn" class="danger">Shut down server</button>251
<button id="admin-shutdown-btn" class="danger">Shut down server</button>@@ -239,8 +239,12 @@ function getMaintenanceSnapshot ()
239
239
const scheduledRestart = typeof restartScheduler.getRestartSchedulerSnapshot === 'function'
240
240
? restartScheduler.getRestartSchedulerSnapshot()
241
241
: null;
242
const uptimeMs = Math.max(0, Math.floor(Number(process.uptime()) * 1000));
243
const startedAt = Date.now() - uptimeMs;
242
244
243
245
return {
246
uptimeMs,
247
startedAt,
244
248
rows: {
245
249
authSessionsTotal: Number(authRows.total || 0),
246
250
authSessionsActive: Number(authRows.active || 0),
@@ -239,8 +239,12 @@ function getMaintenanceSnapshot ()239
const scheduledRestart = typeof restartScheduler.getRestartSchedulerSnapshot === 'function'239
const scheduledRestart = typeof restartScheduler.getRestartSchedulerSnapshot === 'function'240
? restartScheduler.getRestartSchedulerSnapshot()240
? restartScheduler.getRestartSchedulerSnapshot()241
: null;241
: null;242
const uptimeMs = Math.max(0, Math.floor(Number(process.uptime()) * 1000));243
const startedAt = Date.now() - uptimeMs;242
244
243
return {245
return {246
uptimeMs,247
startedAt,244
rows: {248
rows: {245
authSessionsTotal: Number(authRows.total || 0),249
authSessionsTotal: Number(authRows.total || 0),246
authSessionsActive: Number(authRows.active || 0),250
authSessionsActive: Number(authRows.active || 0),@@ -538,6 +538,8 @@ describe('GET /api/admin/debug/stream-stats', () =>
538
538
expect(status).toBe(200);
539
539
expect(Array.isArray(body.videoFiles)).toBe(true);
540
540
expect(body.maintenance).toEqual(expect.objectContaining({
541
uptimeMs: expect.any(Number),
542
startedAt: expect.any(Number),
541
543
rows: expect.objectContaining({
542
544
authSessionsTotal: expect.any(Number),
543
545
shareTokensTotal: expect.any(Number),
@@ -538,6 +538,8 @@ describe('GET /api/admin/debug/stream-stats', () =>538
expect(status).toBe(200);538
expect(status).toBe(200);539
expect(Array.isArray(body.videoFiles)).toBe(true);539
expect(Array.isArray(body.videoFiles)).toBe(true);540
expect(body.maintenance).toEqual(expect.objectContaining({540
expect(body.maintenance).toEqual(expect.objectContaining({541
uptimeMs: expect.any(Number),542
startedAt: expect.any(Number),541
rows: expect.objectContaining({543
rows: expect.objectContaining({542
authSessionsTotal: expect.any(Number),544
authSessionsTotal: expect.any(Number),543
shareTokensTotal: expect.any(Number),545
shareTokensTotal: expect.any(Number),