saved session replays updates and polish
This commit is contained in:
1 parent
1bffb3cbf3
commit
a28ea79228
64 files changed
+170
-111
No files matched your search
@@ -1,12 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { canUpdateWebsite, canViewWebsite } from '@/permissions';
|
||||
import {
|
||||
createReplaySaved,
|
||||
deleteReplaySaved,
|
||||
getReplaySaved,
|
||||
} from '@/queries/prisma/sessionReplay';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getReplayChunks } from '@/queries/sql';
|
||||
|
||||
export async function GET(
|
||||
@@ -25,10 +19,7 @@ export async function GET(
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const [chunks, isSaved] = await Promise.all([
|
||||
getReplayChunks(websiteId, replayId),
|
||||
getReplaySaved(websiteId, replayId),
|
||||
]);
|
||||
const chunks = await getReplayChunks(websiteId, replayId);
|
||||
|
||||
const allEvents = chunks.flatMap(chunk => chunk.events);
|
||||
const sessionId = chunks.length > 0 ? chunks[0].sessionId : null;
|
||||
@@ -42,35 +33,5 @@ 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,60 @@
|
||||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { canUpdateWebsite, canViewWebsite } from '@/permissions';
|
||||
import {
|
||||
createReplaySaved,
|
||||
deleteReplaySaved,
|
||||
getReplaySaved,
|
||||
} from '@/queries/prisma/sessionReplay';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; replayId: string }> },
|
||||
) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId, replayId } = await params;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const isSaved = await getReplaySaved(websiteId, replayId);
|
||||
|
||||
return json({ 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 });
|
||||
}
|
||||
Reference in new issue
Block a user