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>
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { deletePlaySession, endPlaySession, getPlaySessionDetail } from "@/lib/db/queries/play-sessions";
|
||||
import { getRecordingsForSession } from "@/lib/db/queries/recordings";
|
||||
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
||||
import { createLogger } from "@/lib/logger";
|
||||
|
||||
const log = createLogger("play-sessions");
|
||||
const patchSchema = z.object({ status: z.enum(["completed", "aborted"]) });
|
||||
|
||||
export const GET = withRouteLogging(
|
||||
"play-sessions.get",
|
||||
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
const detail = await getPlaySessionDetail(Number(id));
|
||||
if (!detail) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json(detail);
|
||||
},
|
||||
);
|
||||
|
||||
export const PATCH = withRouteLogging(
|
||||
"play-sessions.end",
|
||||
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: "status must be completed or aborted" }, { status: 400 });
|
||||
}
|
||||
const updated = await endPlaySession(Number(id), parsed.data);
|
||||
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ playSession: updated });
|
||||
},
|
||||
);
|
||||
|
||||
export const DELETE = withRouteLogging(
|
||||
"play-sessions.delete",
|
||||
async (req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
const cascade = new URL(req.url).searchParams.get("cascade") === "true";
|
||||
try {
|
||||
await deletePlaySession(Number(id), { cascade });
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
if (message.includes("FOREIGN KEY") || message.includes("SQLITE_CONSTRAINT")) {
|
||||
log.warn("blocked session delete due to referencing recording", { sessionId: id, cascade });
|
||||
const blockingRecordings = await getRecordingsForSession(Number(id));
|
||||
return NextResponse.json(
|
||||
{ error: "cannot delete a session that a saved recording still references", recordings: blockingRecordings },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -1,42 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { deleteRecording, getRecording, renameRecording } from "@/lib/db/queries/recordings";
|
||||
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
||||
|
||||
const patchSchema = z.object({
|
||||
name: z.string().min(1).max(160).optional(),
|
||||
description: z.string().max(2000).optional(),
|
||||
});
|
||||
|
||||
export const GET = withRouteLogging(
|
||||
"recordings.get",
|
||||
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
const result = await getRecording(Number(id));
|
||||
if (!result) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json(result);
|
||||
},
|
||||
);
|
||||
|
||||
export const PATCH = withRouteLogging(
|
||||
"recordings.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: "invalid body" }, { status: 400 });
|
||||
}
|
||||
const updated = await renameRecording(Number(id), parsed.data);
|
||||
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ recording: updated });
|
||||
},
|
||||
);
|
||||
|
||||
export const DELETE = withRouteLogging(
|
||||
"recordings.delete",
|
||||
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
await deleteRecording(Number(id));
|
||||
return NextResponse.json({ ok: true });
|
||||
},
|
||||
);
|
||||
@@ -1,24 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { createRecording, listRecordings } from "@/lib/db/queries/recordings";
|
||||
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
||||
|
||||
const bodySchema = z.object({
|
||||
sourcePlaySessionId: z.number().int().positive(),
|
||||
name: z.string().min(1).max(160),
|
||||
description: z.string().max(2000).optional(),
|
||||
});
|
||||
|
||||
export const GET = withRouteLogging("recordings.list", async () => {
|
||||
const rows = await listRecordings();
|
||||
return NextResponse.json({ recordings: rows });
|
||||
});
|
||||
|
||||
export const POST = withRouteLogging("recordings.create", 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 recording = await createRecording(parsed.data);
|
||||
return NextResponse.json({ recording }, { status: 201 });
|
||||
});
|
||||
@@ -15,7 +15,7 @@ const eventSchema = z.object({
|
||||
const bodySchema = z.object({ events: z.array(eventSchema).max(2000) });
|
||||
|
||||
export const POST = withRouteLogging(
|
||||
"play-sessions.events.append",
|
||||
"sessions.events.append",
|
||||
async (req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
|
||||
@@ -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 });
|
||||
},
|
||||
);
|
||||
@@ -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 });
|
||||
},
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { listPlaySessions, startPlaySession } from "@/lib/db/queries/play-sessions";
|
||||
import { listSessions, startSession } from "@/lib/db/queries/sessions";
|
||||
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
||||
|
||||
const deviceInputSchema = z.object({
|
||||
@@ -11,22 +11,20 @@ const deviceInputSchema = z.object({
|
||||
});
|
||||
|
||||
const bodySchema = z.object({
|
||||
kind: z.enum(["live", "replay"]),
|
||||
replayedRecordingId: z.number().int().positive().optional(),
|
||||
name: z.string().min(1).optional(),
|
||||
devices: z.array(deviceInputSchema).min(1),
|
||||
});
|
||||
|
||||
export const GET = withRouteLogging("play-sessions.list", async () => {
|
||||
const rows = await listPlaySessions();
|
||||
return NextResponse.json({ playSessions: rows });
|
||||
export const GET = withRouteLogging("sessions.list", async () => {
|
||||
const rows = await listSessions();
|
||||
return NextResponse.json({ sessions: rows });
|
||||
});
|
||||
|
||||
export const POST = withRouteLogging("play-sessions.start", async (req: Request) => {
|
||||
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 startPlaySession(parsed.data);
|
||||
const result = await startSession(parsed.data);
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getRecordingLibraryStats } from "@/lib/db/queries/stats";
|
||||
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
||||
|
||||
export const GET = withRouteLogging("stats.recordings", async () => {
|
||||
const stats = await getRecordingLibraryStats();
|
||||
return NextResponse.json(stats);
|
||||
});
|
||||
Reference in New Issue
Block a user