- Fix device rename input collapsing on mobile (fixed width vs w-full inside an auto-layout table column). - Add cascade-delete confirmation for sessions with a saved recording. - Fix header connection LED: derive state from scanning/device-count/ recording instead of the Buttplug client's raw connected flag; drop the label text and hide the indicator entirely when idle. - Add a per-device disconnect button (stop + remove from store, the closest equivalent Buttplug's protocol allows per device). - Fix replay ending early: duration now comes from the recording's actual durationMs, not the last event's timestamp. - Replay robustness: show which devices are being replayed to, reset actuators to zero on start/play/pause, fully disconnect devices and the whole client on stop/unmount, surface command failures via toast. - Stop flagging the header LED red during replay - recording is only for live sessions. - Add page-number pagination to recordings/sessions/devices lists. - Wordmark SEXY -> Sexy; add proper per-page <title>s including dynamic titles for recording/session detail and replay pages. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
44 lines
1.9 KiB
TypeScript
44 lines
1.9 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { deletePlaySession, endPlaySession, getPlaySessionDetail } from "@/lib/db/queries/play-sessions";
|
|
import { getRecordingsForSession } from "@/lib/db/queries/recordings";
|
|
|
|
const patchSchema = z.object({ status: z.enum(["completed", "aborted"]) });
|
|
|
|
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
const detail = await getPlaySessionDetail(Number(id));
|
|
if (!detail) return NextResponse.json({ error: "not found" }, { status: 404 });
|
|
return NextResponse.json(detail);
|
|
}
|
|
|
|
export async function PATCH(req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
const parsed = patchSchema.safeParse(await req.json().catch(() => null));
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: "status must be completed or aborted" }, { status: 400 });
|
|
}
|
|
const updated = await endPlaySession(Number(id), parsed.data);
|
|
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
|
|
return NextResponse.json({ playSession: updated });
|
|
}
|
|
|
|
export async function DELETE(req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
const cascade = new URL(req.url).searchParams.get("cascade") === "true";
|
|
try {
|
|
await deletePlaySession(Number(id), { cascade });
|
|
return NextResponse.json({ ok: true });
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
if (message.includes("FOREIGN KEY") || message.includes("SQLITE_CONSTRAINT")) {
|
|
const blockingRecordings = await getRecordingsForSession(Number(id));
|
|
return NextResponse.json(
|
|
{ error: "cannot delete a session that a saved recording still references", recordings: blockingRecordings },
|
|
{ status: 409 },
|
|
);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|