Files
pinkudex/app/api/whisperjav-verify/route.ts
T
2026-05-26 22:46:00 +02:00

32 lines
1020 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { assertLocalRequest } from "@/lib/api/localOnly";
import { verifyCli, autoDetectCli } from "@/lib/whisperjav/spawn";
import { getAppSetting } from "@/lib/db/appSettings";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(req: NextRequest) {
const blocked = assertLocalRequest(req);
if (blocked) return blocked;
const body = await req.json().catch(() => ({}));
const explicit = typeof body.path === "string" ? body.path.trim() : "";
const autodetect = body.autodetect === true;
let cliPath = explicit;
if (!cliPath && !autodetect) {
cliPath = (getAppSetting("whisperjav").cliPath ?? "").trim();
}
if (!cliPath) {
const detected = await autoDetectCli();
if (!detected) {
return NextResponse.json({ ok: false, error: "whisperjav not found on PATH" });
}
cliPath = detected;
}
const result = await verifyCli(cliPath);
return NextResponse.json(result);
}