-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
63 lines (57 loc) · 1.59 KB
/
route.ts
File metadata and controls
63 lines (57 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { NextResponse } from 'next/server'
import { PrismaClient } from '@/generated/prisma'
const prisma = new PrismaClient()
// GET /api/sessions - List all sessions with pagination
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const page = parseInt(searchParams.get('page') || '1', 10);
const limit = Math.min(parseInt(searchParams.get('limit') || '50', 10), 100); // Max 100 per page
const skip = (page - 1) * limit;
const [sessions, totalCount] = await Promise.all([
prisma.session.findMany({
select: {
id: true,
sandboxId: true,
shareToken: true,
createdAt: true,
updatedAt: true,
},
orderBy: {
createdAt: 'desc'
},
skip,
take: limit,
}),
prisma.session.count(),
]);
return NextResponse.json({
sessions,
pagination: {
page,
limit,
totalCount,
totalPages: Math.ceil(totalCount / limit),
}
});
} catch (error) {
console.error('[API] Failed to fetch sessions:', error)
return NextResponse.json(
{ error: 'Failed to fetch sessions' },
{ status: 500 }
)
}
}
// DELETE /api/sessions - Delete all sessions
export async function DELETE() {
try {
await prisma.session.deleteMany()
return NextResponse.json({ success: true })
} catch (error) {
console.error('[API] Failed to delete all sessions:', error)
return NextResponse.json(
{ error: 'Failed to delete sessions' },
{ status: 500 }
)
}
}