saved session replay implementation checkpoint
This commit is contained in:
1 parent
81fd8e63a1
commit
1bffb3cbf3
21 files changed
+392
-78
No files matched your search
@@ -1,6 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { canUpdateWebsite, canViewWebsite } from '@/permissions';
|
||||
import {
|
||||
createReplaySaved,
|
||||
deleteReplaySaved,
|
||||
getReplaySaved,
|
||||
} from '@/queries/prisma/sessionReplay';
|
||||
import { getReplayChunks } from '@/queries/sql';
|
||||
|
||||
export async function GET(
|
||||
@@ -19,7 +25,10 @@ export async function GET(
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const chunks = await getReplayChunks(websiteId, replayId);
|
||||
const [chunks, isSaved] = await Promise.all([
|
||||
getReplayChunks(websiteId, replayId),
|
||||
getReplaySaved(websiteId, replayId),
|
||||
]);
|
||||
|
||||
const allEvents = chunks.flatMap(chunk => chunk.events);
|
||||
const sessionId = chunks.length > 0 ? chunks[0].sessionId : null;
|
||||
@@ -33,5 +42,35 @@ export async function GET(
|
||||
endedAt,
|
||||
eventCount: allEvents.length,
|
||||
chunkCount: chunks.length,
|
||||
isSaved,
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; replayId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
isSaved: z.boolean(),
|
||||
name: z.string().max(100).optional(),
|
||||
});
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId, replayId } = await params;
|
||||
|
||||
if (!(await canUpdateWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
if (body.isSaved) {
|
||||
await createReplaySaved(websiteId, replayId, body.name ?? '');
|
||||
} else {
|
||||
await deleteReplaySaved(websiteId, replayId);
|
||||
}
|
||||
|
||||
return json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { pagingParams, searchParams } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getSavedReplays } from '@/queries/prisma/sessionReplay';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
...searchParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getSavedReplays(websiteId, query);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
Reference in new issue
Block a user