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.
91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
// What a player went through, for the client log (E22 S5) — one definition for every player, so a
|
|
// stall in the Plex player and one in the library player read the same in a diagnosis.
|
|
//
|
|
// A media ERROR is a warning at every level: it is the thing a user reports. The rest — play, pause,
|
|
// buffering, seeking, the end, metadata, rate — is Részletes (DEBUG) and costs nothing below it.
|
|
// Positions are whole seconds; nothing here names what is playing (the request log already has the
|
|
// item's route template, and a title is the user's content).
|
|
import { useCallback, useRef } from "react";
|
|
|
|
import { enabled, log } from "./log";
|
|
|
|
const MEDIA_EVENTS = [
|
|
"loadedmetadata",
|
|
"play",
|
|
"pause",
|
|
"waiting",
|
|
"stalled",
|
|
"seeking",
|
|
"seeked",
|
|
"ratechange",
|
|
"ended",
|
|
"emptied",
|
|
"error",
|
|
] as const;
|
|
|
|
/** Log `media`'s playback events as `player`. Returns the detach. */
|
|
export function logMediaElement(media: HTMLMediaElement, player: string): () => void {
|
|
const onEvent = (e: Event) => {
|
|
const at = Math.round(media.currentTime || 0);
|
|
if (e.type === "error") {
|
|
const err = media.error;
|
|
log.warn("player.media_error", `${player} media error ${err?.code ?? "?"}`, {
|
|
player,
|
|
code: err?.code ?? null,
|
|
message: err?.message || null,
|
|
at,
|
|
});
|
|
return;
|
|
}
|
|
if (!enabled("DEBUG")) return;
|
|
const attrs: Record<string, unknown> = { player, event: e.type, at };
|
|
if (e.type === "ratechange") attrs.rate = media.playbackRate;
|
|
if (e.type === "loadedmetadata" && Number.isFinite(media.duration)) {
|
|
attrs.duration = Math.round(media.duration);
|
|
}
|
|
log.debug("player.media", `${player} ${e.type}`, attrs);
|
|
};
|
|
for (const type of MEDIA_EVENTS) media.addEventListener(type, onEvent);
|
|
return () => {
|
|
for (const type of MEDIA_EVENTS) media.removeEventListener(type, onEvent);
|
|
};
|
|
}
|
|
|
|
/** A ref callback that logs the element it is given (and stops when React hands it null). */
|
|
export function useMediaLogRef(player: string): (media: HTMLMediaElement | null) => void {
|
|
const detach = useRef<(() => void) | null>(null);
|
|
return useCallback(
|
|
(media: HTMLMediaElement | null) => {
|
|
detach.current?.();
|
|
detach.current = media ? logMediaElement(media, player) : null;
|
|
},
|
|
[player],
|
|
);
|
|
}
|
|
|
|
// The IFrame API's numeric player states, named (https://developers.google.com/youtube/iframe_api_reference).
|
|
const YT_STATES: Record<number, string> = {
|
|
[-1]: "unstarted",
|
|
0: "ended",
|
|
1: "playing",
|
|
2: "paused",
|
|
3: "buffering",
|
|
5: "cued",
|
|
};
|
|
|
|
/** The YouTube player changed state (DEBUG). */
|
|
export function logYouTubeState(state: number, at: number): void {
|
|
if (!enabled("DEBUG")) return;
|
|
const name = YT_STATES[state] ?? String(state);
|
|
log.debug("player.media", `youtube ${name}`, {
|
|
player: "youtube",
|
|
event: name,
|
|
at: Math.round(at),
|
|
});
|
|
}
|
|
|
|
/** The YouTube player refused the video — 2 bad id, 5 HTML5 error, 100 gone, 101/150 embed denied. */
|
|
export function logYouTubeError(code: number): void {
|
|
log.warn("player.media_error", `youtube error ${code}`, { player: "youtube", code });
|
|
}
|