From 103e039f969237b9251f8d4ae6e27f6c38353661 Mon Sep 17 00:00:00 2001 From: Avanti Date: Sun, 6 Dec 2026 20:26:52 +0530 Subject: [PATCH 1/2] fix(admin): show storage count window and 24h default label (#1322) --- .changeset/admin-storage-panel-window.md | 4 + crates/nostream-admin/tests/console_parity.rs | 99 +++++++++++++++++++ resources/admin/assets/admin-ops.js | 41 +++++++- resources/admin/dashboard.html | 5 +- 4 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 .changeset/admin-storage-panel-window.md diff --git a/.changeset/admin-storage-panel-window.md b/.changeset/admin-storage-panel-window.md new file mode 100644 index 000000000..b20fc26f9 --- /dev/null +++ b/.changeset/admin-storage-panel-window.md @@ -0,0 +1,4 @@ +--- +--- + +fix(admin): show storage count window and 24h default label (#1322) diff --git a/crates/nostream-admin/tests/console_parity.rs b/crates/nostream-admin/tests/console_parity.rs index 2d4273748..067eab657 100644 --- a/crates/nostream-admin/tests/console_parity.rs +++ b/crates/nostream-admin/tests/console_parity.rs @@ -470,3 +470,102 @@ fn a_missing_console_file_is_a_failure() { assert!(!assets_dir().join(missing).exists()); let _ = ADMIN_BASE; } + +/// The storage-count panel renders the reply's `since`/`until` window beside the count and labels +/// defaulted requests (`last 24 h`), rather than presenting a 24 h slice as the store total (#1322). +#[test] +fn the_storage_panel_renders_the_window_it_reports() { + let html = std::fs::read_to_string(dashboard_html()).expect("dashboard.html"); + let start = html + .find(">Storage counts") + .expect("Storage counts section"); + let end = html[start..] + .find("") + .expect("closing ") + + start; + let section = &html[start..end]; + assert!( + !section.contains("optional since/until unix seconds"), + "storage copy must state the 24 h default: {section}" + ); + assert!(section.contains("Window")); + assert!(section.contains("colspan=\"3\"")); + + let script = r#" +const fs = require('fs'); +class El { + constructor(tag) { + this.tagName = tag.toUpperCase(); this.children = []; this.innerHTML = ''; this.textContent = ''; + this.value = ''; this.disabled = false; + this.classList = { set: new Set(), add(c){this.set.add(c)}, remove(c){this.set.delete(c)}, contains(c){return this.set.has(c)} }; + this.listeners = {}; + } + addEventListener(ev, fn) { (this.listeners[ev] ||= []).push(fn); } + replaceChildren(...nodes) { this.children = nodes; } + append() {} +} +const kinds = new El('input'); kinds.value = '1'; +const since = new El('input'); +const until = new El('input'); +const runBtn = new El('button'); +const errEl = new El('div'); +const body = new El('tbody'); +const byId = { + 'ops-workers-body': new El('tbody'), 'ops-storage-kinds': kinds, 'ops-storage-since': since, + 'ops-storage-until': until, 'ops-storage-run': runBtn, 'ops-storage-error': errEl, 'ops-storage-body': body, +}; +global.document = { getElementById: (id) => byId[id] || null, createElement: (t) => new El(t) }; +global.window = { __ADMIN_DASHBOARD__: { pathPrefix: '' } }; +global.HTMLElement = El; +let nextPayload; +global.fetch = async () => ({ status: 200, ok: true, json: async () => nextPayload }); +eval(fs.readFileSync(process.argv[1], 'utf8')); +const flush = () => new Promise((r) => setTimeout(r, 15)); +const assertHas = (hay, needle) => { if (!hay.includes(needle)) throw new Error(`expected ${JSON.stringify(needle)} in ${hay}`); }; +const assertLacks = (hay, needle) => { if (hay.includes(needle)) throw new Error(`did not expect ${JSON.stringify(needle)} in ${hay}`); }; +(async () => { + nextPayload = { since: 1700000000, until: 1700086400, counts: [{ kinds: [1], count: 42 }] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, '42'); + assertHas(body.innerHTML, 'last 24 h (2023-11-14 22:13:20 UTC – 2023-11-15 22:13:20 UTC)'); + + since.value = '1700000000'; until.value = '1700172800'; + nextPayload = { since: 1700000000, until: 1700172800, counts: [{ kinds: [1], count: 99 }] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, '99'); + assertHas(body.innerHTML, '2023-11-14 22:13:20 UTC – 2023-11-16 22:13:20 UTC'); + assertLacks(body.innerHTML, 'last 24 h'); + + since.value = ''; until.value = '1700086400'; + nextPayload = { since: 1700000000, until: 1700086400, counts: [{ kinds: [1], count: 7 }] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, 'default 24 h (2023-11-14 22:13:20 UTC – 2023-11-15 22:13:20 UTC)'); + + since.value = '0'; until.value = '3600'; + nextPayload = { since: 0, until: 3600, counts: [{ kinds: [1], count: 3 }] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, '1970-01-01 00:00:00 UTC – 1970-01-01 01:00:00 UTC'); + + nextPayload = { since: 0, until: 3600, counts: [] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, 'colspan="3"'); +})().catch((err) => { console.error(err); process.exit(1); }); +"#; + let output = std::process::Command::new("node") + .arg("-e") + .arg(script) + .arg(assets_dir().join("admin-ops.js")) + .output() + .expect("run node storage panel harness"); + assert!( + output.status.success(), + "node storage panel harness failed:\nstdout: {}\nstderr: {}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); +} diff --git a/resources/admin/assets/admin-ops.js b/resources/admin/assets/admin-ops.js index db08005cb..b070b7196 100644 --- a/resources/admin/assets/admin-ops.js +++ b/resources/admin/assets/admin-ops.js @@ -157,18 +157,46 @@ } } - const renderStorage = (counts) => { + const formatBound = (seconds) => { + if (typeof seconds !== 'number' || !Number.isFinite(seconds)) { + return '—' + } + return formatTime(new Date(seconds * 1000).toISOString()) + } + + const formatStorageWindow = (windowRange, { defaultedSince = false, defaultedUntil = false } = {}) => { + const hasSince = typeof windowRange?.since === 'number' && Number.isFinite(windowRange.since) + const hasUntil = typeof windowRange?.until === 'number' && Number.isFinite(windowRange.until) + if (!hasSince || !hasUntil) { + return '—' + } + const range = `${formatBound(windowRange.since)} – ${formatBound(windowRange.until)}` + if (defaultedSince && defaultedUntil) { + return `last 24 h (${range})` + } + if (defaultedSince) { + return `default 24 h (${range})` + } + if (defaultedUntil) { + return `${range} (until defaulted to now)` + } + return range + } + + const renderStorage = (counts, windowRange, options = {}) => { if (!Array.isArray(counts) || !counts.length) { elements.storageBody.innerHTML = - 'No counts returned.' + 'No counts returned.' return } + const windowLabel = formatStorageWindow(windowRange, options) elements.storageBody.innerHTML = counts .map( (row) => ` ${escapeHtml((row.kinds ?? []).join(', '))} ${escapeHtml(row.count)} + ${escapeHtml(windowLabel)} `, ) .join('') @@ -252,8 +280,8 @@ } const params = new URLSearchParams({ kinds }) - const since = elements.storageSince?.value - const until = elements.storageUntil?.value + const since = elements.storageSince?.value?.trim() ?? '' + const until = elements.storageUntil?.value?.trim() ?? '' if (since) { params.set('since', since) } @@ -267,7 +295,10 @@ showStorageError(payload.error ?? 'Storage count query failed') return } - renderStorage(payload.counts) + renderStorage(payload.counts, payload, { + defaultedSince: !since, + defaultedUntil: !until, + }) } const reverify = async (pubkey) => { diff --git a/resources/admin/dashboard.html b/resources/admin/dashboard.html index ef046457c..b53688728 100644 --- a/resources/admin/dashboard.html +++ b/resources/admin/dashboard.html @@ -314,7 +314,7 @@

NIP-05 verifications

Storage counts

-

Per-kind counts use NIP-45-style filters (comma-separated kinds, optional since/until unix seconds).

+

Per-kind counts use NIP-45-style filters (comma-separated kinds; since/until unix seconds default to the last 24 h when omitted).

@@ -338,10 +338,11 @@

Storage counts

Kinds Count + Window - Run a query to load counts. + Run a query to load counts.
From 5afad2582cbb052f0847ed5ef59b628fb25840af Mon Sep 17 00:00:00 2001 From: Avanti Date: Sun, 6 Dec 2026 20:50:57 +0530 Subject: [PATCH 2/2] fix(admin): handle out-of-range storage bound timestamps (#1322) --- crates/nostream-admin/tests/console_parity.rs | 7 +++++++ resources/admin/assets/admin-ops.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/nostream-admin/tests/console_parity.rs b/crates/nostream-admin/tests/console_parity.rs index 067eab657..cbb962a52 100644 --- a/crates/nostream-admin/tests/console_parity.rs +++ b/crates/nostream-admin/tests/console_parity.rs @@ -550,6 +550,13 @@ const assertLacks = (hay, needle) => { if (hay.includes(needle)) throw new Error await flush(); assertHas(body.innerHTML, '1970-01-01 00:00:00 UTC – 1970-01-01 01:00:00 UTC'); + since.value = '10000000000000'; until.value = '10000000000001'; + nextPayload = { since: 10000000000000, until: 10000000000001, counts: [{ kinds: [1], count: 5 }] }; + runBtn.listeners.click[0](); + await flush(); + assertHas(body.innerHTML, '5'); + assertHas(body.innerHTML, '10000000000000 – 10000000000001'); + nextPayload = { since: 0, until: 3600, counts: [] }; runBtn.listeners.click[0](); await flush(); diff --git a/resources/admin/assets/admin-ops.js b/resources/admin/assets/admin-ops.js index b070b7196..458099aa6 100644 --- a/resources/admin/assets/admin-ops.js +++ b/resources/admin/assets/admin-ops.js @@ -161,7 +161,8 @@ if (typeof seconds !== 'number' || !Number.isFinite(seconds)) { return '—' } - return formatTime(new Date(seconds * 1000).toISOString()) + const date = new Date(seconds * 1000) + return Number.isNaN(date.getTime()) ? String(seconds) : formatTime(date.toISOString()) } const formatStorageWindow = (windowRange, { defaultedSince = false, defaultedUntil = false } = {}) => {