2025-08-28 11:34:44 +08:00

26 lines
772 B
TypeScript

import { NextResponse } from "next/server";
import { readdir, stat } from "node:fs/promises";
import { WEBSITE_FILE_DIR } from "@/lib/config";
export const runtime = "nodejs";
export async function GET() {
try {
const entries = await readdir(WEBSITE_FILE_DIR, { withFileTypes: true });
const dirs: string[] = [];
for (const e of entries) {
if (e.isDirectory()) {
// 仅列出存在 log/access.log 的站点
try {
const s = await stat(`${WEBSITE_FILE_DIR}/${e.name}/log/access.log`);
if (s.isFile()) dirs.push(e.name);
} catch {}
}
}
dirs.sort();
return NextResponse.json({ sites: dirs });
} catch (error) {
return NextResponse.json({ error: String(error) }, { status: 500 });
}
}