Next.js app with a browser-side buttplug/buttplug-wasm control layer (server never touches real-time device commands), SQLite storage via Drizzle, single-secret auth, recordings/replay with device remapping, a usage stats dashboard, Docker deployment, and Gitea CI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W8WkFF5ppURBAB918593Eb
25 lines
951 B
TypeScript
25 lines
951 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { insertEvents } from "@/lib/db/queries/session-events";
|
|
|
|
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 async function POST(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 });
|
|
}
|