Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getVideoIndex, rescanVideoIndex, getCodesWithVideos, getCodesWithSubtitles } from "@/lib/video";
|
||||
import { getAppSetting } from "@/lib/db/appSettings";
|
||||
import { assertLocalRequest } from "@/lib/api/localOnly";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* Lightweight enumeration of every JAV code that has at least one
|
||||
* playable file in the index. The client uses this to show "has video"
|
||||
* badges on cover cards. Returned as a plain array for JSON portability.
|
||||
*
|
||||
* Auto-builds the index on first hit if a video folder is configured but
|
||||
* the index is empty — avoids requiring a manual rescan on a fresh
|
||||
* server boot.
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
const blocked = assertLocalRequest(req);
|
||||
if (blocked) return blocked;
|
||||
|
||||
let idx = getVideoIndex();
|
||||
const main = (getAppSetting("videoLibraryPath") || "").trim();
|
||||
const extras = getAppSetting("videoExtraPaths") ?? [];
|
||||
const expected = [main, ...extras].filter(Boolean);
|
||||
const haveAll = expected.length === idx.rootsScanned.length
|
||||
&& expected.every((r, i) => r === idx.rootsScanned[i]);
|
||||
if (expected.length > 0 && !haveAll) {
|
||||
idx = await rescanVideoIndex();
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
codes: Array.from(getCodesWithVideos()),
|
||||
subtitleCodes: Array.from(getCodesWithSubtitles()),
|
||||
count: idx.count,
|
||||
lastScannedAt: idx.lastScannedAt,
|
||||
rootsScanned: idx.rootsScanned,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user