Files
sexy/app/api/sessions/[id]/events/route.ts
T
valknarandClaude Sonnet 5 401b9b5033
CI / Build and push image (push) Successful in 1m41s
CI / Static checks (push) Successful in 2m12s
Remove recordings feature, replay sessions directly, bump to 0.6.0
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>
2026-08-27 21:38:51 +02:00

29 lines
1.1 KiB
TypeScript

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