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 });
}
}

View File

@@ -0,0 +1,39 @@
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 formData = await req.formData();
const file = formData.get("file") as File;
const slot = formData.get("slot") as string;
if (!file) {
return NextResponse.json({ error: "No file uploaded" }, { status: 400 });
}
// Simulate firmware processing
console.log(`[FIRMWARE] Uploading ${file.name} to ${id} (Slot ${slot})`);
// Update device record to reflect new firmware (simulated)
const updatedDevice = await prisma.device.update({
where: { id },
data: {
firmwareVersion: "1.2.0-RC", // Simulated version bump
activeSlot: slot || undefined
}
});
return NextResponse.json({
success: true,
version: "1.2.0-RC",
slot: updatedDevice.activeSlot
});
} catch (error) {
console.error("Firmware upload error:", error);
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}

View File

@@ -7,13 +7,14 @@ export async function PATCH(
) {
try {
const { id } = await params;
const { status, name } = await req.json();
const { status, name, activeSlot } = await req.json();
const device = await prisma.device.update({
where: { id },
data: {
status: status || undefined,
name: name || undefined
name: name || undefined,
activeSlot: activeSlot || undefined
},
});