// settings.serviceCookies — the PROACTIVE side of the cookie refresh alerts // (plans/cookie-refresh-alerts.md, controller/serviceCookieTimer.ts): how often // the editor looks at each service's cookies by itself, so a stale Rumble // clearance is noticed before a sync or a download fails on it. Pure: the // type, its defaults, the sanitizer settingsSchema.ts runs it through and the // per-field docs SETTINGS.md renders. import type { FieldDocs } from "./fieldDocs"; export type ServiceCookiesSettings = { recheckIntervalMinutes: number; probeServices: string[]; }; export const SERVICE_COOKIE_RECHECK_DEFAULT_MINUTES = 180; // Below half an hour a "proactive" probe is a poll; above a day it notices // nothing a sync would not. export const SERVICE_COOKIE_RECHECK_MIN_MINUTES = 30; export const SERVICE_COOKIE_RECHECK_MAX_MINUTES = 1440; // The yt-dlp services a tick may probe with no alert up. export const SERVICE_COOKIE_PROBE_SERVICES = ["rumble", "youtube", "odysee"] as const; export const DEFAULT_SERVICE_COOKIES_SETTINGS: ServiceCookiesSettings = { recheckIntervalMinutes: SERVICE_COOKIE_RECHECK_DEFAULT_MINUTES, probeServices: ["rumble"], }; export const SERVICE_COOKIES_SETTINGS_FIELD_DOCS: FieldDocs = { recheckIntervalMinutes: "Every this many minutes (stretched by up to `pacing.jitter`, never shortened) the editor looks at each " + "service's cookies by itself (common/controller/serviceCookieTimer.ts): every RAISED cookie alert that has " + "something to ask is rechecked once, as the banner's Recheck does (so a banner clears by itself once the " + "operator has opened the site in the browser); each of `probeServices` with no alert is probed once — one " + "metadata request for the last video it answered cleanly — so a stale Cloudflare clearance raises the banner " + "before a sync or a download fails on it; and X's cookie jar is re-read from disk (never a request to X). A " + "service is skipped when a job is queued or running on its platform (that job is the probe), when it is " + "cooling down or held, when it answered cleanly within the interval, or when a recheck of it is already " + "running. A failed probe is never retried: the banner goes up (a Rumble embed 403 confirms on a second, " + "different known-good video, once, a jittered minute or more later) and waits for the next tick or a manual " + "Recheck. 0 turns the timer off; otherwise " + `${SERVICE_COOKIE_RECHECK_MIN_MINUTES}–${SERVICE_COOKIE_RECHECK_MAX_MINUTES}. Default ` + `${SERVICE_COOKIE_RECHECK_DEFAULT_MINUTES}. Not armed on an idle boot (ARCHILYZER_IDLE_BOOT) or on the e2e ` + "test server. `pnpm ops get services` shows its last tick (`timer`).", probeServices: "The yt-dlp services the timer probes with no alert up — any of " + `${SERVICE_COOKIE_PROBE_SERVICES.map((s) => `\`"${s}"\``).join(", ")}. Default \`["rumble"]\` (Rumble's ` + "Cloudflare clearance is the one that goes stale by itself). `[]` probes nothing; raised alerts are still " + "rechecked.", }; export function clampServiceCookieRecheckMinutes(v: unknown): number { if (typeof v !== "number" || !Number.isFinite(v)) return SERVICE_COOKIE_RECHECK_DEFAULT_MINUTES; const n = Math.floor(v); if (n <= 0) return 0; return Math.min(SERVICE_COOKIE_RECHECK_MAX_MINUTES, Math.max(SERVICE_COOKIE_RECHECK_MIN_MINUTES, n)); } export function sanitizeServiceCookies(value: unknown): ServiceCookiesSettings { const r = (value && typeof value === "object" && !Array.isArray(value) ? value : {}) as Record; const known = SERVICE_COOKIE_PROBE_SERVICES as readonly string[]; const probeServices = Array.isArray(r.probeServices) ? [...new Set(r.probeServices.filter((s): s is string => typeof s === "string" && known.includes(s)))] : [...DEFAULT_SERVICE_COOKIES_SETTINGS.probeServices]; return { recheckIntervalMinutes: clampServiceCookieRecheckMinutes(r.recheckIntervalMinutes), probeServices, }; }