// CONNECT A FORUM SESSION — the one body behind the forum channel page's // "Connect forum session" (channels/[slug]/socialActions.ts) and the /cookies // row of a forum host (cookies/actions.ts): a HEADED browser window on the // host's profile (common/social/forumSession.ts), opened at a thread on the // machine running the editor, for the operator to clear a check and close. A // window that closed on the thread clears the host's cookie refresh alert. // Through the one-press-per-service guard (lib/cookieRefreshGuard.ts). import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { connectForumSession, type ForumSessionRecord } from "yt-dlp-transcript-common/social/forumSession"; import { noteServiceCookieClean } from "yt-dlp-transcript-common/lib/serviceCookies-server"; import { forumServiceKey } from "yt-dlp-transcript-common/lib/serviceCookies"; import { withCookieAction } from "./cookieRefreshGuard"; export type ConnectForumResult = { ok: true; record: ForumSessionRecord } | { ok: false; error: string }; export async function connectForumAt(url: string, host: string, channel?: string): Promise { const service = forumServiceKey(host); return withCookieAction( service, "connect", async (): Promise => { try { const record = await connectForumSession(getPaths(), url, { onLog: (line) => console.log(`[forum-session] ${line}`), }); if (record.cleared) { await noteServiceCookieClean(getPaths(), service, { url, ...(channel ? { channel } : {}) }, { by: "connect" }); } return { ok: true, record }; } catch (e) { return { ok: false, error: (e as Error).message }; } }, (r) => r.ok ? { ok: true, message: r.record.cleared ? `Connected: the window closed on the thread (${r.record.cookies} cookies).` : "The window closed before the thread showed: not cleared.", } : { ok: false, message: r.error }, ); }