"use server"; // /settings → Network exits (lane network-exits). Each action is the twin of a // `pnpm ops` call: save → `pnpm ops network`, assign → `pnpm ops network-exit`, // probe → `pnpm ops get network --probe`. No answer holds a secret: the // settings never do (credentials live in network.credentialsFile). import { revalidatePath } from "next/cache"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { NetworkInputError, assignChannelExit, networkReport, probeNetworkExits, type NetworkReportView, } from "yt-dlp-transcript-common/controller/networkExits"; import { NetworkSaveError, saveNetworkRequest } from "./networkSave"; import { directEcho } from "./networkProbe"; export type NetworkReport = NetworkReportView; type Answer = { ok: true; report: NetworkReport } | { ok: false; error: string }; async function report(): Promise { // Built from the stored, secret-free form (controller/networkExits.ts). return networkReport(getPaths()); } function refusal(e: unknown): { ok: false; error: string } { if (e instanceof NetworkSaveError || e instanceof NetworkInputError) return { ok: false, error: e.message }; return { ok: false, error: (e as Error).message ?? String(e) }; } export async function networkReportAction(): Promise { return report(); } export async function saveNetworkAction(body: Record): Promise { try { await saveNetworkRequest(body); revalidatePath("/settings"); return { ok: true, report: await report() }; } catch (e) { return refusal(e); } } export async function assignChannelExitAction(slug: string, exit: string): Promise { try { await assignChannelExit({ paths: getPaths(), slug, exit }); return { ok: true, report: await report() }; } catch (e) { return refusal(e); } } export async function probeNetworkAction(): Promise { try { await probeNetworkExits(getPaths(), undefined, new Date(), { explicit: true, getDirect: directEcho }); return { ok: true, report: await report() }; } catch (e) { return refusal(e); } }