feat: Settings → Diagnostics, a consented log level and the tab's own log
A user can raise their diagnostics level to Részletes (DEBUG) or Teljes (TRACE) for 24 hours from a new Settings tab, after a consent box that says what is recorded, that the server keeps it and for how long (the instance's own retention), and that it lapses. Alap is the base and needs no consent. - users.diagnostics_level/_until (migration 0087), written only by PUT /api/me/diagnostics, which computes the expiry itself; the demo account cannot raise it. /api/me reports the level in force. - The server logs an elevated user's requests at that level and stores every line of them (logs.LevelGate on the stdout handler and the sink; the root is lowered only while an elevation is active). Teljes adds the redacted query string to the request line. - POST /api/diagnostics/events stores the browser's log as source=web rows: account from the session, body capped while streaming, events/attrs capped, re-redacted, events under the consented level dropped, timestamps clamped, 30 batches a minute, 409 once the level lapsed. - lib/diagnostics.ts applies the level to the tab and streams only what happens after consent, in batches, never its own request lines, with a keepalive flush on pagehide; stops on lapse (its own timer), on withdrawal and on 409. - Detail hooks at DEBUG: which control was clicked (test id, icon, app copy in English — never user text, input values or a link's query), visibility/bfcache/resize, filter changes (lib/filterLog.ts; typed search only at TRACE), player events (lib/mediaLog.ts; media errors are warnings at every level). Offline/online at the base level. - "Saját napló" viewer: live, newest first, level groups with counts, search, row details, copy the filtered events as JSON lines, clear. - Privacy policy and Terms exist in Hungarian and English (a contract test holds both languages to the same sections); the policy now describes the server logs and diagnostic logging, self-service deletion and password sign-in. Fixed on the way: - A sync auth dependency ran logs.set_user on a copied context, so the account never reached a handler's own log lines (measured); a per-request mutable scope carries it now. - The Settings tab rail left a phone no room (clipped labels, buttons over text): below `sm` it is a scrolling row above the content. - PUT /api/me/preferences took a bare dict body; it is a Pydantic model now.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// The signed-in account & session: the bootstrap `me` probe, multi-account switch/list, sign-out,
|
||||
// app version, and preference save. Only touches core's req.
|
||||
import { req } from "./core";
|
||||
import type { DiagnosticsState } from "./diagnostics";
|
||||
|
||||
export interface Me {
|
||||
id: number;
|
||||
@@ -28,6 +29,8 @@ export interface Me {
|
||||
/** Admin-only: false when SMTP is incomplete, so every outbound message is silently skipped. */
|
||||
email_configured: boolean;
|
||||
preferences: Record<string, unknown>;
|
||||
/** The consented diagnostics level in force and when it lapses (E22 S5). */
|
||||
diagnostics: DiagnosticsState;
|
||||
}
|
||||
|
||||
export interface Account {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// The user's diagnostics level (E22 S5) and the browser log it lets out. Only touches core's req and
|
||||
// beacon. The streaming itself — what is sent, when, and when it stops — is `lib/diagnostics.ts`.
|
||||
import type { LogEvent } from "../log";
|
||||
import { beacon, req } from "./core";
|
||||
|
||||
/** Alap / Részletes / Teljes. The server decides how long a raised level lasts. */
|
||||
export type DiagnosticsLevel = "INFO" | "DEBUG" | "TRACE";
|
||||
|
||||
export interface DiagnosticsState {
|
||||
level: DiagnosticsLevel;
|
||||
/** When a raised level lapses back to INFO (ISO); null at INFO. */
|
||||
until: string | null;
|
||||
/** How many days this instance keeps stored log lines — the consent text states it. */
|
||||
retention_days: number;
|
||||
}
|
||||
|
||||
/** Where batches go. The shipper leaves the log lines ABOUT this request out of what it sends, or
|
||||
* every batch would carry the previous batch's request line forever. */
|
||||
export const DIAGNOSTICS_EVENTS_PATH = "/api/diagnostics/events";
|
||||
|
||||
export const diagnosticsApi = {
|
||||
setDiagnosticsLevel: (
|
||||
level: DiagnosticsLevel,
|
||||
): Promise<{ ok: true; diagnostics: DiagnosticsState }> =>
|
||||
req("/api/me/diagnostics", { method: "PUT", body: JSON.stringify({ level }) }),
|
||||
// Quiet: a lost batch is not the user's problem to be told about in a dialog.
|
||||
sendLogEvents: (events: LogEvent[]): Promise<{ ok: true; stored: number }> =>
|
||||
req(
|
||||
DIAGNOSTICS_EVENTS_PATH,
|
||||
{ method: "POST", body: JSON.stringify({ events }) },
|
||||
{ quiet: true },
|
||||
),
|
||||
/** The last batch of a closing tab (keepalive, fire-and-forget). */
|
||||
sendLogEventsOnUnload: (events: LogEvent[]): void => beacon(DIAGNOSTICS_EVENTS_PATH, { events }),
|
||||
};
|
||||
@@ -32,6 +32,7 @@ const SLICE_MODULES = [
|
||||
["plexApi", () => import("./plex")],
|
||||
["messagingApi", () => import("./messaging")],
|
||||
["downloadsApi", () => import("./downloads")],
|
||||
["diagnosticsApi", () => import("./diagnostics")],
|
||||
] as const;
|
||||
|
||||
let api: Slice;
|
||||
|
||||
Reference in New Issue
Block a user