feat: Implement device firmware and command APIs, add individual device administration page, and refine UI styling.

This commit is contained in:
2025-12-22 23:59:02 -05:00
parent dae7926eaa
commit 7d82a9e223
11 changed files with 579 additions and 80 deletions

View File

@@ -0,0 +1,44 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function POST(
req: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const { command } = await req.json();
// In a real implementation, this would communicate with the hardware
// For now, we simulate success and update the database accordingly
const device = await prisma.device.findUnique({
where: { id }
});
if (!device) {
return NextResponse.json({ error: "Device not found" }, { status: 404 });
}
switch (command) {
case "REBOOT":
// Simulate reboot logic
console.log(`[DEVICE CMD] Rebooting device ${device.serialNumber}`);
break;
case "SHUTDOWN":
// Simulate shutdown logic
console.log(`[DEVICE CMD] Shutting down device ${device.serialNumber}`);
await prisma.device.update({
where: { id },
data: { status: "OFFLINE" }
});
break;
default:
return NextResponse.json({ error: "Unknown command" }, { status: 400 });
}
return NextResponse.json({ success: true, command });
} catch (error) {
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}