POC for playwright based screenshots for heatmaps
This commit is contained in:
1 parent
1f3f805a30
commit
6de5adaefc
12 files changed
+938
-1139
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { notFound, unauthorized } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getHeatmapSnapshotImage } from '@/queries/sql/heatmap/ensureHeatmapSnapshot';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; snapshotId: string }> },
|
||||
) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
const { websiteId, snapshotId } = await params;
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const snapshot = await getHeatmapSnapshotImage(websiteId, snapshotId);
|
||||
|
||||
if (!snapshot) {
|
||||
return notFound({ message: 'Snapshot not found.' });
|
||||
}
|
||||
|
||||
return new Response(new Uint8Array(snapshot.imageData), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': snapshot.mimeType,
|
||||
'Cache-Control': 'private, max-age=300',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user