Remove recordings feature, replay sessions directly, bump to 0.6.0
CI / Build and push image (push) Successful in 1m41s
CI / Static checks (push) Successful in 2m12s

Recordings were just a thin named pointer over an already-captured
session's events, so the whole separate feature (recordings table, API
routes, pages, UI) is gone: any completed session can now be named and
replayed directly. Replaying no longer creates a session or duplicates
events of its own - it just bumps the source session's playCount/lastPlayedAt.

Also renames play_sessions/playSession(s) to sessions/session(s) throughout
the schema, queries, API routes, and UI for consistency, and updates the
README to match the new flow.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 21:38:51 +02:00
co-authored by Claude Sonnet 5
parent 2a3c4ff1f2
commit 401b9b5033
46 changed files with 1710 additions and 1018 deletions
+28
View File
@@ -0,0 +1,28 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { insertEvents } from "@/lib/db/queries/session-events";
import { withRouteLogging } from "@/lib/api/with-route-logging";
const eventSchema = z.object({
sessionDeviceId: z.number().int().positive(),
tsMs: z.number().int().min(0),
commandType: z.enum(["vibrate", "rotate", "linear", "stop"]),
featureIndex: z.number().int().min(0),
value: z.number().min(0).max(1),
durationMs: z.number().int().positive().optional(),
});
const bodySchema = z.object({ events: z.array(eventSchema).max(2000) });
export const POST = withRouteLogging(
"sessions.events.append",
async (req: Request, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
}
await insertEvents(Number(id), parsed.data.events);
return NextResponse.json({ inserted: parsed.data.events.length });
},
);
+31
View File
@@ -0,0 +1,31 @@
import { NextResponse } from "next/server";
import { getSessionForReplay, incrementSessionPlayCount } from "@/lib/db/queries/sessions";
import { withRouteLogging } from "@/lib/api/with-route-logging";
export const GET = withRouteLogging(
"sessions.replay-data",
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
const result = await getSessionForReplay(Number(id));
if (!result) return NextResponse.json({ error: "not found" }, { status: 404 });
if (result.session.durationMs === null) {
return NextResponse.json({ error: "session has no recorded duration yet" }, { status: 409 });
}
return NextResponse.json(result);
},
);
/**
* Marks the session as replayed (bumps playCount/lastPlayedAt). Replaying
* itself creates no session row or events of its own - the client just
* plays this session's already-recorded events back against newly-mapped
* devices, so this is the only DB write a replay run causes.
*/
export const POST = withRouteLogging(
"sessions.replay-start",
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
await incrementSessionPlayCount(Number(id), Date.now());
return NextResponse.json({ ok: true });
},
);
+56
View File
@@ -0,0 +1,56 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { deleteSession, endSession, getSessionDetail, renameSession } from "@/lib/db/queries/sessions";
import { withRouteLogging } from "@/lib/api/with-route-logging";
const patchSchema = z
.object({
status: z.enum(["completed", "aborted"]).optional(),
name: z.string().min(1).max(160).optional(),
description: z.string().max(2000).optional(),
})
.refine((v) => v.status !== undefined || v.name !== undefined || v.description !== undefined, {
message: "at least one of status, name, description is required",
});
export const GET = withRouteLogging(
"sessions.get",
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
const detail = await getSessionDetail(Number(id));
if (!detail) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json(detail);
},
);
export const PATCH = withRouteLogging(
"sessions.update",
async (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: parsed.error.message }, { status: 400 });
}
const { status, name, description } = parsed.data;
let updated;
if (status !== undefined) {
updated = await endSession(Number(id), { status });
}
if (name !== undefined || description !== undefined) {
updated = await renameSession(Number(id), { name, description });
}
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ session: updated });
},
);
export const DELETE = withRouteLogging(
"sessions.delete",
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params;
await deleteSession(Number(id));
return NextResponse.json({ ok: true });
},
);
+30
View File
@@ -0,0 +1,30 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { listSessions, startSession } from "@/lib/db/queries/sessions";
import { withRouteLogging } from "@/lib/api/with-route-logging";
const deviceInputSchema = z.object({
slotLabel: z.string().min(1),
bleName: z.string().min(1),
deviceClass: z.string().nullish(),
capabilities: z.object({ outputs: z.array(z.string()), featureCount: z.number() }).optional(),
});
const bodySchema = z.object({
name: z.string().min(1).optional(),
devices: z.array(deviceInputSchema).min(1),
});
export const GET = withRouteLogging("sessions.list", async () => {
const rows = await listSessions();
return NextResponse.json({ sessions: rows });
});
export const POST = withRouteLogging("sessions.start", async (req: Request) => {
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
}
const result = await startSession(parsed.data);
return NextResponse.json(result, { status: 201 });
});