import { NextResponse } from "next/server"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { noteDriveSlow, recordLocationHealth, registerLocationHealth, } from "yt-dlp-transcript-common/lib/storageHealth"; import { forgetChannelMedia } from "yt-dlp-transcript-common/lib/channelMedia"; import { resetStorageProbeMemo } from "yt-dlp-transcript-common/controller/storageLocations"; import { testRouteDenied } from "../_guard"; export const dynamic = "force-dynamic"; // E2E test harness only (guarded by `E2E_TEST_ROUTES`, see _guard.ts). // // A STALLED DRIVE WITHOUT A HUNG MOUNT. No fixture can make a real drive stop // answering, and none should: this records what a detector would have said // about a configured location — `stalled` (one answer marks it, as the // counters or the watchdog would) or `slow` (the watchdog's slow refusal) — // into the process's health record, which every gate, page and poll reads. // The health pass then sees the fixture's drive answering and clears a stall // after `clearAfterCleanPasses` passes (30 s at the defaults), so a spec // asserts within that window. `/api/test/invalidate-cache` forgets it all. // // POST {"id": "", "state": "stalled" | "slow", "cause"?: "…"} export async function POST(req: Request) { const denied = testRouteDenied(); if (denied) return denied; const body = (await req.json().catch(() => ({}))) as { id?: string; state?: string; cause?: string; }; const loc = getSettings().storage.locations.find((l) => l.id === body.id); if (!loc) { return NextResponse.json({ error: `no storage location "${body.id}"` }, { status: 404 }); } registerLocationHealth([loc]); if (body.state === "stalled") { recordLocationHealth(loc, "stalled", { cause: body.cause ?? "a read in the editor did not answer within 3 s", }); } else if (body.state === "slow") { noteDriveSlow(loc.id, body.cause ?? "a read in the editor took 2.4 s"); } else { return NextResponse.json({ error: `state must be "stalled" or "slow"` }, { status: 400 }); } // The channels' five-second answers and the ten-second probes, so the next // page sees the drive as it is now. forgetChannelMedia(); resetStorageProbeMemo(); return NextResponse.json({ ok: true }); }