This commit is contained in:
2025-12-31 17:18:50 +01:00
parent 8e8b8a6a87
commit 5bd0c6ba3b
2 changed files with 43 additions and 4 deletions
+17
View File
@@ -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<NextResponse> {
const auth = await testAuth(req);
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
return NextResponse.json(await getAllContainerLogs());
}
+26 -4
View File
@@ -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 */}
<div className="flex flex-wrap items-center gap-2">
<Button variant="outline" size="sm" className="gap-2">
{/* <Button variant="outline" size="sm" className="gap-2">
<Filter className="w-4 h-4" />
<span className="hidden sm:inline">Advanced Filter</span>
</Button>
</Button> */}
<Button variant="outline" size="sm" className="gap-2">
<Download className="w-4 h-4" />
<span className="hidden sm:inline">Export</span>
<span className="hidden sm:inline" onClick={handleExport}>
Export
</span>
</Button>
<div className="hidden md:block w-px h-6 bg-border" />