Container stats and actions
This commit is contained in:
@@ -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",
|
||||
});
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user