Download src/app/api/activity/route.ts from simikkk/test8: direct link, hf CLI and curl.
- Browser
- Download file 890 Bytes
-
https://huggingface.co/spaces/simikkk/test8/resolve/main/src/app/api/activity/route.ts
- Command line
-
hf download hf://spaces/simikkk/test8/src/app/api/activity/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/simikkk/test8/resolve/main/src/app/api/activity/route.ts
890 Bytes
| import { NextRequest, NextResponse } from 'next/server'; | |
| import { withDb } from '@/lib/api-handler'; | |
| import { db } from '@/lib/db'; | |
| import { getCookieToken, getSessionUser } from '@/lib/auth'; | |
| async function handler(req: NextRequest) { | |
| try { | |
| const token = getCookieToken(req); | |
| if (!token) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | |
| const user = await getSessionUser(token); | |
| if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | |
| const logs = await db.activityLog.findMany({ | |
| where: { userId: user.id }, | |
| orderBy: { createdAt: 'desc' }, | |
| take: 50, | |
| }); | |
| return NextResponse.json({ activities: logs }); | |
| } catch (error) { | |
| console.error('Activity fetch error:', error); | |
| return NextResponse.json({ error: 'Internal error' }, { status: 500 }); | |
| } | |
| } | |
| export const GET = withDb(handler); |