73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { requireRequestSession } from "@/lib/boss-auth";
|
|
import { applyProjectConflictDecision, updateDevice } from "@/lib/boss-data";
|
|
|
|
export async function PATCH(
|
|
request: NextRequest,
|
|
context: { params: Promise<{ deviceId: string }> },
|
|
) {
|
|
const session = await requireRequestSession(request);
|
|
if (!session) {
|
|
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
|
|
}
|
|
const { deviceId } = await context.params;
|
|
const body = (await request.json()) as {
|
|
name?: string;
|
|
avatar?: string;
|
|
account?: string;
|
|
status?: "online" | "abnormal" | "offline";
|
|
endpoint?: string;
|
|
note?: string;
|
|
projects?: string[];
|
|
capabilities?: {
|
|
gui?: {
|
|
connected?: boolean;
|
|
lastSeenAt?: string;
|
|
lastActiveProjectId?: string;
|
|
};
|
|
cli?: {
|
|
connected?: boolean;
|
|
lastSeenAt?: string;
|
|
lastActiveProjectId?: string;
|
|
};
|
|
browserAutomation?: {
|
|
connected?: boolean;
|
|
lastSeenAt?: string;
|
|
lastActiveProjectId?: string;
|
|
};
|
|
computerUse?: {
|
|
connected?: boolean;
|
|
lastSeenAt?: string;
|
|
lastActiveProjectId?: string;
|
|
};
|
|
codexAppServer?: {
|
|
connected?: boolean;
|
|
lastSeenAt?: string;
|
|
lastActiveProjectId?: string;
|
|
};
|
|
};
|
|
preferredExecutionMode?: "gui" | "cli";
|
|
projectId?: string;
|
|
folderKey?: string;
|
|
conflictDecision?: "forbid" | "allow_once" | "allow_always";
|
|
};
|
|
|
|
try {
|
|
if (body.conflictDecision && body.projectId) {
|
|
await applyProjectConflictDecision({
|
|
deviceId,
|
|
projectId: body.projectId,
|
|
folderKey: body.folderKey,
|
|
decision: body.conflictDecision,
|
|
});
|
|
}
|
|
const device = await updateDevice(deviceId, body);
|
|
return NextResponse.json({ ok: true, device });
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ ok: false, message: error instanceof Error ? error.message : "UNKNOWN_ERROR" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
}
|