diff --git a/src/app/api/logs/route.ts b/src/app/api/logs/route.ts new file mode 100644 index 0000000..23dd21e --- /dev/null +++ b/src/app/api/logs/route.ts @@ -0,0 +1,17 @@ +import { NextRequest, NextResponse } from "next/server"; +import testAuth from "../auth"; +import { StatusCodes } from "http-status-codes"; +import { getAllContainerLogs } from "@/core/server/docker"; + +export async function GET(req: NextRequest): Promise { + const auth = await testAuth(req); + + if (auth) { + return NextResponse.json( + { message: auth }, + { status: StatusCodes.UNAUTHORIZED } + ); + } + + return NextResponse.json(await getAllContainerLogs()); +} diff --git a/src/app/logs/page.tsx b/src/app/logs/page.tsx index c9bc202..514a9d4 100644 --- a/src/app/logs/page.tsx +++ b/src/app/logs/page.tsx @@ -19,7 +19,7 @@ export default function LogsPage() { useEffect(() => { const fetch = async () => { - setLogs(await getAllContainerLogs()); + if (!isPaused) setLogs(await getAllContainerLogs()); }; const iid = setInterval(fetch, 1000); @@ -33,6 +33,26 @@ export default function LogsPage() { filter === "all" ? true : log.level === filter ); + const handleExport = () => { + // Convert data to JSON string + const json = JSON.stringify(filteredLogs, null, 2); + + // Create a blob from the JSON + const blob = new Blob([json], { type: "application/json" }); + + // Create a temporary URL for the blob + const url = URL.createObjectURL(blob); + + // Create a temporary link and click it + const link = document.createElement("a"); + link.href = url; + link.download = "logs.json"; // File name + link.click(); + + // Cleanup + URL.revokeObjectURL(url); + }; + const getLevelClass = (level: string) => { switch (level) { case "info": @@ -90,13 +110,15 @@ export default function LogsPage() { {/* Actions */}
- + */}