2026-08-25 07:51:38 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
import { createRecording, listRecordings } from "@/lib/db/queries/recordings";
|
2026-08-26 08:45:15 +02:00
|
|
|
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
2026-08-25 07:51:38 +02:00
|
|
|
|
|
|
|
|
const bodySchema = z.object({
|
|
|
|
|
sourcePlaySessionId: z.number().int().positive(),
|
|
|
|
|
name: z.string().min(1).max(160),
|
|
|
|
|
description: z.string().max(2000).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const GET = withRouteLogging("recordings.list", async () => {
|
2026-08-25 07:51:38 +02:00
|
|
|
const rows = await listRecordings();
|
|
|
|
|
return NextResponse.json({ recordings: rows });
|
2026-08-26 08:45:15 +02:00
|
|
|
});
|
2026-08-25 07:51:38 +02:00
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const POST = withRouteLogging("recordings.create", async (req: Request) => {
|
2026-08-25 07:51:38 +02:00
|
|
|
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
const recording = await createRecording(parsed.data);
|
|
|
|
|
return NextResponse.json({ recording }, { status: 201 });
|
2026-08-26 08:45:15 +02:00
|
|
|
});
|