first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { safeJoinSitePath } from "@/lib/config";
|
||||
import { analyzeLogs } from "@/lib/analyzeLogs";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET(
|
||||
_req: Request,
|
||||
ctx: { params: Promise<{ dir: string }> }
|
||||
) {
|
||||
try {
|
||||
const { dir } = await ctx.params;
|
||||
const filePath = safeJoinSitePath(dir, "log", "access.log");
|
||||
const content = await readFile(filePath, { encoding: "utf-8" });
|
||||
const data = await analyzeLogs(content);
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: String(error) }, { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { safeJoinSitePath } from "@/lib/config";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET(
|
||||
_req: Request,
|
||||
ctx: { params: Promise<{ dir: string }> }
|
||||
) {
|
||||
try {
|
||||
const { dir } = await ctx.params;
|
||||
const filePath = safeJoinSitePath(dir, "log", "access.log");
|
||||
const content = await readFile(filePath, { encoding: "utf-8" });
|
||||
return new NextResponse(content, { headers: { "content-type": "text/plain; charset=utf-8" } });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: String(error) }, { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user