feat(webui): per-widget config — alerts levels/count, sessions sort/filter (phase 5)

Overview widgets can carry an opaque `config` (stored per grid item). v1:
- alerts: how many entries + which log levels (was fixed at 5 warn/error);
  the alert row colour now uses the full 6-level palette instead of a
  warn/error binary.
- sessions: sort (recent / uin / nickname) + a nickname/uin filter.

A gear in the layout editor opens an inline config form per configurable
widget; edits apply live (no grid re-init — config isn't in the grid key) and
persist via the section-merge save. Config is parsed client-side with total,
clamping parsers (count 1-50, known levels only, filter <=100 chars); the
server stores it opaquely within a 4KB bound. Widgets with no config render
exactly as before. Verified across 2 adversarial review rounds.
This commit is contained in:
DrSmoothl committed 2026-06-13 21:17:23 +08:00
1 parent f07f309c51
commit 3258300539
6 files changed
+233 -50

No files matched your search

+13
View File
@@ -102,6 +102,12 @@ export interface UiLayoutItem {
y?: number;
w?: number;
h?: number;
/**
* Per-widget settings (overview blocks only) — an opaque object the client
* interprets by widget type (e.g. alerts: count + levels). The server only
* checks it's a plain object within a size bound; it never reads the keys.
*/
config?: Record<string, unknown>;
}
export interface UiLayout {
@@ -245,6 +251,13 @@ function normalizeLayoutItems(value: unknown, fallback: UiLayoutItem[]): UiLayou
item.w = clampInt(raw.w, 1, 12, 1);
item.h = clampInt(raw.h, 1, 100, 1);
}
// Opaque per-widget config: keep only a plain object within a size bound;
// the server never interprets the keys (the client does, per widget type).
if (isObject(raw.config)) {
try {
if (JSON.stringify(raw.config).length <= 4096) item.config = raw.config;
} catch { /* unserializable (cycles) → drop */ }
}
out.push(item);
}
// An array that parsed to nothing usable is indistinguishable from corrupt;