2026-04-13 00:46:58 -06:00
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
import { execSync } from "child_process";
|
|
|
|
|
import { auth } from "@/lib/auth";
|
2026-04-13 00:59:10 -06:00
|
|
|
import { memo } from "@/lib/cache";
|
2026-04-13 00:46:58 -06:00
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
|
|
|
|
export async function GET(req: NextRequest) {
|
|
|
|
|
const session = await auth();
|
|
|
|
|
if (!session) {
|
|
|
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const lines = Math.min(
|
|
|
|
|
parseInt(req.nextUrl.searchParams.get("lines") || "50"),
|
|
|
|
|
200
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try {
|
2026-04-13 00:59:10 -06:00
|
|
|
const logs = memo(`logs:${lines}`, 2000, () =>
|
|
|
|
|
execSync(`sudo journalctl -u minecraft.service --no-pager -n ${lines}`, {
|
|
|
|
|
encoding: "utf8",
|
|
|
|
|
timeout: 5000,
|
|
|
|
|
})
|
2026-04-13 00:46:58 -06:00
|
|
|
);
|
|
|
|
|
return NextResponse.json({ logs });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return NextResponse.json(
|
|
|
|
|
{ error: (e as Error).message },
|
|
|
|
|
{ status: 500 }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|