Download src/app/api/admin/logs/route.ts from HonzaH/Letschat: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/app/api/admin/logs/route.ts
- Command line
-
hf download hf://spaces/HonzaH/Letschat/src/app/api/admin/logs/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/app/api/admin/logs/route.ts
1.44 kB
| import { NextRequest, NextResponse } from 'next/server' | |
| import { createServiceClient } from 'lib/supabase/server' | |
| const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN | |
| export async function GET(request: NextRequest) { | |
| if (!ADMIN_API_TOKEN) { | |
| return NextResponse.json({ error: 'ADMIN_API_TOKEN není nastaven' }, { status: 503 }) | |
| } | |
| const authHeader = request.headers.get('authorization') || '' | |
| const token = authHeader.toLowerCase().startsWith('bearer ') | |
| ? authHeader.slice(7) | |
| : request.headers.get('x-admin-token') || '' | |
| if (token !== ADMIN_API_TOKEN) { | |
| return NextResponse.json({ error: 'Neautorizováno' }, { status: 401 }) | |
| } | |
| if (!process.env.SUPABASE_SERVICE_ROLE_KEY || !process.env.SUPABASE_URL) { | |
| return NextResponse.json({ error: 'Supabase service role není k dispozici' }, { status: 503 }) | |
| } | |
| try { | |
| const supabase = createServiceClient() | |
| const { data, error } = await supabase | |
| .from('logs' as any) | |
| .select('id, created_at, module, operation, level, error') | |
| .order('created_at', { ascending: false }) | |
| .limit(200) | |
| if (error) { | |
| return NextResponse.json({ error: 'Nepodařilo se načíst logy', detail: error.message }, { status: 500 }) | |
| } | |
| return NextResponse.json({ logs: data || [] }) | |
| } catch (e: any) { | |
| console.error('Admin logs error:', e) | |
| return NextResponse.json({ error: 'Vnitřní chyba serveru' }, { status: 500 }) | |
| } | |
| } | |