import { NextRequest, NextResponse } from "next/server"; import { execSync } from "child_process"; import { auth } from "@/lib/auth"; 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 { const logs = execSync( `sudo journalctl -u minecraft.service --no-pager -n ${lines}`, { encoding: "utf8", timeout: 5000 } ); return NextResponse.json({ logs }); } catch (e) { return NextResponse.json( { error: (e as Error).message }, { status: 500 } ); } }