// THE DASHBOARD'S COOKIE REFRESH ALERTS (plans/cookie-refresh-alerts.md): the // state file read, each recorded job's status asked of the registry (else its // sidecar), and the pure builder (lib/serviceCookies.ts) over both. Served as // the `cookieAlerts` view and SSR-seeded by app/page.tsx. Beside the alerts: // X's jar age read from disk (`x` — always, so `pnpm ops get services` says // how fresh X's login is) and the proactive recheck timer's last tick // (`timer`, controller/serviceCookieTimer.ts). import { getPaths, type Paths } from "yt-dlp-transcript-common/lib/paths"; import { getRegistry } from "yt-dlp-transcript-common/jobs/registry"; import { readJobMeta } from "yt-dlp-transcript-common/jobs/jobMeta"; import { buildServiceCookieAlerts, type ServiceCookieAlertsPayload, } from "yt-dlp-transcript-common/lib/serviceCookies"; import { configuredCookieBrowser, readServiceCookieState, } from "yt-dlp-transcript-common/lib/serviceCookies-server"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { readXJarAge } from "yt-dlp-transcript-common/social/xJarAge"; import { resolvedXMaxCookieAgeMinutes } from "yt-dlp-transcript-common/jobs/networkGuard"; import { serviceCookieTimerView } from "yt-dlp-transcript-common/controller/serviceCookieTimer"; export async function loadCookieAlerts( paths: Paths = getPaths(), now: number = Date.now(), ): Promise { const state = await readServiceCookieState(paths); const ids = new Set(); for (const e of Object.values(state.services)) { if (!e.raisedAt) continue; for (const j of e.jobs) ids.add(j.id); } // Only a job that can be retried (it carries a replay descriptor) is one // "Re-run stopped jobs" can offer: a lane's unit or a one-off without a spec // has no status here, so it is never listed as stopped. const statuses = new Map(); const registry = getRegistry(); for (const id of ids) { const live = registry.get(id); const meta = live ? null : await readJobMeta(paths, id); const status = live?.status ?? meta?.status; const replayable = Boolean(live?.spec ?? meta?.spec); if (status && replayable) statuses.set(id, status); } // Never a request: a stat of the profile's jar, or (browser login) a cached // name-only read of Firefox's store. A read that fails leaves `x` out. let settings: ReturnType | null = null; try { settings = getSettings(); } catch { settings = null; } let x: Awaited> | undefined; if (settings) { try { x = await readXJarAge(paths, settings, { maxAgeMinutes: resolvedXMaxCookieAgeMinutes(settings), now }); } catch { /* no X login to read */ } } const payload = buildServiceCookieAlerts(state, { now, browser: configuredCookieBrowser(), statusOf: (id) => statuses.get(id), ...(x ? { xJar: x } : {}), }); if (x) payload.x = x; payload.timer = serviceCookieTimerView(settings?.serviceCookies.recheckIntervalMinutes); return payload; }