// THE COOKIES SCREEN'S ROWS (editor /cookies, plans/cookie-screen.md): one row // per service the editor reads cookies for — X, Rumble, YouTube, Odysee, // archive.today and each forum host — saying where its cookies come from, how // old they are, whether its cookie alert is up, how the last press ended, and // the ONE thing to press. // // Client-safe and pure: the reads are editor/app/lib/cookieStatus.ts, which // hands this builder what it read and the privacy displayers (every path and // spec drawn goes through them — settings.privacy decides what a home path or // a user name looks like). // // THE ONE BUTTON PER ROW, and what it runs (each the existing action): // x, connected profile Refresh cookies refreshXCookies (headless; loads x.com/home) // x, no profile yet Connect X account (a HEADED window on the editor's machine) // x, browser login Check again recheck "x" — no request; the line says open x.com // rumble / youtube / odysee Check again recheck — one request; the line says open the site // archive.today Connect archive session (headed) // a forum host Connect forum session (headed), at a thread the app has met import type { ServiceCookieAction, ServiceCookieAlertsPayload, ServiceCookieState, XJarStatusView } from "./serviceCookies"; import { forumServiceKey, serviceFamily, serviceLabel, type ServiceFamily } from "./serviceCookies"; import type { BrowserCookieAge } from "./browserCookieAge"; export type CookieRowState = "stale" | "fine" | "unknown"; export type CookieRowButton = { action: "refresh" | "connect" | "recheck"; label: string; // Why it cannot be pressed, when it cannot. disabled?: string; }; export type CookieRow = { service: string; label: string; family: ServiceFamily; // Where the cookies come from, already through the privacy displayers. source: string; // How old they are: `ageAt` is the time, `ageVerb` what happened then // ("jar written"); `age` the sentence at readAt ("jar written 12 min ago"). ageVerb: string | null; ageAt: string | null; ageMinutes: number | null; age: string | null; // The age limit or expiry, as a clause ("limit 60 min", "expires 10:40 UTC"). ageNote?: string; // Why the age is not known, when it is not. ageUnknown?: string; state: CookieRowState; // The alert's sentence (or the pending first signal's), when there is one. alert?: string; // What to do by hand, in one line, where no button does it. todo?: string; // The button opens a window on the machine running the editor. headed?: boolean; button: CookieRowButton | null; last?: ServiceCookieAction; running?: CookieRunning; // A forum host's thread channels (each one's page carries its retry and // import controls; each one's Connect opens at its own thread). channels?: string[]; }; export type CookieRunning = { action: CookieRowButton["action"]; since: string; jobId?: string }; // X'S SITTING AND ACCOUNT (lane x-sittings), for the X row's panel: the // sitting since the last refresh (jobs/xSitting.ts) and the account's state // as the operator marked it (social/xAccountState.ts). export type XSittingView = { began: string | null; kind: "timelines" | "browse" | "unknown" | null; used: number; left: number; limit: number; unreadable?: true; account: { state: "ok" | "suspended"; since?: string; note?: string; alert?: string }; // X's 15 minutes after a 429, when it is cooling down. cooldownUntil?: string; }; export type CookieStatusPayload = { readAt: string; rows: CookieRow[]; xSitting?: XSittingView }; export type Displayers = { path: (p: string) => string; text: (s: string) => string }; export type YtdlpCookieInput = { // The cookiesFromBrowser yt-dlp uses for this service, and where it is set. spec?: string; specFrom: "channel" | "settings"; channel?: string; age: BrowserCookieAge; }; export type CookieStatusInput = { now: number; alerts: ServiceCookieAlertsPayload; state: ServiceCookieState; x: { source: "profile" | "browser"; browserSpec?: string; profileDir: string; hasProfile: boolean; // The exported jar holds an X login (auth_token). loggedIn?: boolean; jar?: XJarStatusView; }; ytdlp: Record<"rumble" | "youtube" | "odysee", YtdlpCookieInput>; archive: { dir: string; hasProfile: boolean; connectedAt?: string; cleared?: boolean }; forums: { host: string; dir: string; hasProfile: boolean; connectedAt?: string; cleared?: boolean }[]; // The forum-thread channels, by host (each with its thread URL). forumChannels?: { host: string; slug: string; url: string }[]; running: Record; display: Displayers; }; export const HEADED_NOTE = "Opens a browser window on the editor's machine, not on this device."; // "12 min", "3 h", "16 days". export function durationText(min: number): string { if (min < 1) return "less than a minute"; if (min < 120) return `${min} min`; const h = Math.floor(min / 60); return h < 48 ? `${h} h` : `${Math.floor(h / 24)} days`; } export function minutesSince(at: string | null | undefined, now: number): number | null { if (!at) return null; const t = Date.parse(at); return Number.isFinite(t) ? Math.max(0, Math.floor((now - t) / 60_000)) : null; } // "jar written 12 min ago" — the client re-derives it every tick. export function ageSentence(verb: string | null, at: string | null, now: number): string | null { const m = minutesSince(at, now); if (!verb || m === null) return null; return m < 1 ? `${verb} just now` : `${verb} ${durationText(m)} ago`; } function hhmm(at: string): string { return `${at.slice(11, 16)} UTC`; } function browserWord(spec: string | undefined): string { const s = spec?.trim() ?? ""; if (!s) return "the browser"; if (s.startsWith("file:")) return "a browser"; return s.split(/[:+]/)[0] || s; } const SITE: Record<"rumble" | "youtube" | "odysee", string> = { rumble: "rumble.com", youtube: "youtube.com", odysee: "odysee.com", }; function alertFields( service: string, input: CookieStatusInput, ): { state: CookieRowState | null; alert?: string } { const a = input.alerts.alerts.find((x) => x.service === service); // A fix sentence may name a cookies file: drawn through the displayers too. if (a?.state === "stale") return { state: "stale", alert: input.display.text(a.headline) }; if (a?.state === "ok-again") return { state: "fine", alert: input.display.text(a.headline) }; const p = input.alerts.pending.find((x) => x.service === service); if (p) { return { state: null, alert: `One ${p.kind === "embed-403" ? "embed 403" : p.kind} at ${hhmm(p.lastSeen)}; a second video raises the alert.`, }; } return { state: null }; } export function buildCookieStatus(input: CookieStatusInput): CookieStatusPayload { const { now, display } = input; const rows: CookieRow[] = []; const last = (service: string) => { const a = input.state.actions?.[service]; return a ? { last: { ...a, message: display.text(a.message) } } : {}; }; const common = (service: string) => ({ service, label: serviceLabel(service), family: serviceFamily(service), ...last(service), ...(input.running[service] ? { running: input.running[service] } : {}), }); const aged = (verb: string | null, at: string | null) => ({ ageVerb: at ? verb : null, ageAt: at, ageMinutes: minutesSince(at, now), age: ageSentence(verb, at, now), }); const settle = (known: boolean, a: ReturnType): CookieRowState => a.state ?? (known ? "fine" : "unknown"); // ── X ── { const x = input.x; const a = alertFields("x", input); const jar = x.jar; if (x.source === "profile") { const at = jar?.at ?? null; rows.push({ ...common("x"), source: `Connected profile (${display.path(x.profileDir)})`, ...aged("jar written", at), ...(jar ? { ageNote: jar.maxAgeMinutes > 0 ? `limit ${jar.maxAgeMinutes} min` : "no age limit" } : {}), ...(!at ? { ageUnknown: x.hasProfile ? "No cookie jar exported yet." : "No X profile connected yet." } : {}), state: settle(!!at, a), ...(a.alert ? { alert: a.alert } : {}), // Refresh re-exports a LOGGED-IN profile; with no login in it yet the // one press is the login itself. ...(x.hasProfile && x.loggedIn !== false ? { button: { action: "refresh", label: "Refresh cookies" } } : { headed: true, todo: HEADED_NOTE, button: { action: "connect", label: "Connect X account" } }), }); } else { const at = jar?.at ?? null; const b = browserWord(x.browserSpec); rows.push({ ...common("x"), source: `Browser login (${display.text(x.browserSpec ?? "no cookiesFromBrowser set")})`, ...aged("login last used", at), ...(jar && jar.maxAgeMinutes > 0 ? { ageNote: `limit ${jar.maxAgeMinutes} min` } : {}), ...(!at ? { ageUnknown: jar?.summary ? display.text(jar.summary) : "Not read." } : {}), state: settle(!!at, a), ...(a.alert ? { alert: a.alert } : {}), todo: `Open x.com in ${b}, then Check again (no request is sent to X).`, button: { action: "recheck", label: "Check again" }, }); } } // ── the yt-dlp services ── for (const svc of ["rumble", "youtube", "odysee"] as const) { const y = input.ytdlp[svc]; const a = alertFields(svc, input); const verb = y.age.basis === "file" ? "cookies file written" : y.age.basis === "clearance" ? "clearance issued" : "sign-in last used"; const at = y.age.at; const exp = y.age.expiresAt; const expMin = exp ? Math.floor((Date.parse(exp) - now) / 60_000) : null; const entry = input.state.services[svc]; const canAsk = !!input.state.lastGood[svc] || !!entry?.evidence.url; const lastGood = input.state.lastGood[svc]; const ageUnknown = y.age.unknown ? display.text(y.age.unknown) : y.age.found === false ? `No ${svc === "youtube" ? "sign-in" : "clearance"} cookie for ${SITE[svc]} in ${browserWord(y.spec)}.` : undefined; rows.push({ ...common(svc), source: y.spec ? `${display.text(y.spec)} (${y.specFrom === "channel" && y.channel ? `channel ${y.channel}` : "cookiesFromBrowser"})` : "No browser cookies (cookiesFromBrowser is not set)", ...aged(verb, at), ...(expMin !== null ? { ageNote: expMin > 0 ? `expires in ${durationText(expMin)}` : `expired ${durationText(-expMin)} ago` } : {}), ...(ageUnknown && !at ? { ageUnknown } : {}), state: settle(!!at || !!lastGood, a), ...(a.alert ? { alert: a.alert } : lastGood ? { alert: `Last clean request ${durationText(minutesSince(lastGood.at, now) ?? 0)} ago.` } : {}), todo: `Open ${SITE[svc]} in ${browserWord(y.spec)}${svc === "youtube" ? " signed in" : ""}, then Check again.`, button: { action: "recheck", label: "Check again", ...(canAsk ? {} : { disabled: `No ${serviceLabel(svc)} request is recorded yet to ask again.` }), }, }); } // ── archive.today ── { const ar = input.archive; const a = alertFields("archive.today", input); const at = ar.connectedAt ?? null; rows.push({ ...common("archive.today"), source: `Archive profile (${display.path(ar.dir)})`, ...aged("connected", at), ...(at ? { ageNote: ar.cleared ? "check passed" : "check not passed" } : {}), ...(!at ? { ageUnknown: ar.hasProfile ? "Profile present, never connected here." : "Never connected." } : {}), state: settle(!!at, a), ...(a.alert ? { alert: a.alert } : {}), headed: true, todo: HEADED_NOTE, button: { action: "connect", label: "Connect archive session" }, }); } // ── each forum host ── const hosts = new Map(); for (const f of input.forums) hosts.set(forumServiceKey(f.host), f); for (const key of [...Object.keys(input.state.services), ...Object.keys(input.state.lastGood)]) { if (serviceFamily(key) === "forum" && !hosts.has(key)) hosts.set(key, null); } const byHost = new Map(); for (const c of input.forumChannels ?? []) { const key = forumServiceKey(c.host); if (!hosts.has(key)) hosts.set(key, null); byHost.set(key, [...(byHost.get(key) ?? []), { slug: c.slug, url: c.url }]); } for (const [host, f] of [...hosts.entries()].sort(([a], [b]) => a.localeCompare(b))) { const a = alertFields(host, input); const at = f?.connectedAt ?? null; const entry = input.state.services[host]; const channels = (byHost.get(host) ?? []).map((c) => c.slug).sort(); const thread = input.state.lastGood[host]?.url ?? entry?.evidence.url ?? byHost.get(host)?.[0]?.url; rows.push({ ...common(host), source: f ? `Forum profile (${display.path(f.dir)})` : "No forum profile yet", ...aged("connected", at), ...(at ? { ageNote: f?.cleared ? "check passed" : "check not passed" } : {}), ...(!at ? { ageUnknown: f?.hasProfile ? "Profile present, never connected here." : "Never connected." } : {}), state: settle(!!at, a), ...(a.alert ? { alert: a.alert } : {}), headed: true, todo: HEADED_NOTE, button: { action: "connect", label: "Connect forum session", ...(thread ? {} : { disabled: "No thread on this forum is recorded yet: connect from the thread's channel page." }), }, ...(channels.length ? { channels } : {}), }); } return { readAt: new Date(now).toISOString(), rows }; } // The thread a forum host's Connect opens at: the last clean page, else the // page that met the check, else the first thread channel on the host. export function forumThreadFor( state: ServiceCookieState, host: string, channels: readonly { host: string; slug: string; url: string }[] = [], ): { url: string; channel?: string } | null { const good = state.lastGood[host]; if (good) return { url: good.url, ...(good.channel ? { channel: good.channel } : {}) }; const e = state.services[host]; if (e?.evidence.url) return { url: e.evidence.url, ...(e.evidence.channel ? { channel: e.evidence.channel } : {}) }; const c = channels.find((x) => forumServiceKey(x.host) === host); return c ? { url: c.url, channel: c.slug } : null; }