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>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
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 });
|
|
},
|
|
);
|