Container stats and actions

This commit is contained in:
2025-12-30 13:40:36 +01:00
parent baddd5e4a2
commit 7dd0dca73c
7 changed files with 198 additions and 24 deletions
+54
View File
@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../../auth";
import { StatusCodes } from "http-status-codes";
import { startContainer, stopContainer } from "@/core/server/docker";
export async function POST(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
const id = req.nextUrl.searchParams.get("containerId");
if (!id) {
return NextResponse.json(
{ message: "Invalid containerId param" },
{ status: StatusCodes.BAD_REQUEST }
);
}
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
await startContainer(id);
return NextResponse.json({
message: "ok",
});
}
export async function DELETE(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
const id = req.nextUrl.searchParams.get("containerId");
if (!id) {
return NextResponse.json(
{ message: "Invalid containerId param" },
{ status: StatusCodes.BAD_REQUEST }
);
}
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
await stopContainer(id);
return NextResponse.json({
message: "ok",
});
}
+33
View File
@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../../auth";
import { StatusCodes } from "http-status-codes";
import { getContainerStats } from "@/core/server/docker";
export async function GET(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
const id = req.nextUrl.searchParams.get("containerId");
if (!id) {
return NextResponse.json(
{ message: "Invalid containerId param" },
{ status: StatusCodes.BAD_REQUEST }
);
}
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
const stats = await getContainerStats(id);
return NextResponse.json({
message: "ok",
stats: {
cpu_stats: stats?.cpu_stats,
memory_stats: stats?.memory_stats,
},
});
}