import { NextResponse, type NextRequest } from 'next/server'; import { requireAdminApi } from '@/lib/auth/admin-guard'; import { getSupabaseAdmin } from '@/lib/supabase/admin'; import { logAdminAction } from '@/lib/auth/audit'; import { isUuid } from '@/lib/admin/validators'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; export async function POST( _req: NextRequest, { params }: { params: { id: string } }, ) { const auth = await requireAdminApi(); if (!auth.ok) return auth.response; const { id } = params; if (!isUuid(id)) { return NextResponse.json({ error: 'invalid tunnel id' }, { status: 400 }); } const admin = getSupabaseAdmin(); const { data, error } = await admin .from('tunnels') .update({ bytes_used: 0 }) .eq('id', id) .select('subdomain') .maybeSingle<{ subdomain: string }>(); if (error) { return NextResponse.json({ error: error.message }, { status: 500 }); } if (!data) { return NextResponse.json({ error: 'tunnel not found' }, { status: 404 }); } await logAdminAction(auth.user, { action: 'tunnel.reset_usage', target_type: 'tunnel', target_id: id, details: { subdomain: data.subdomain }, }); return NextResponse.json({ ok: true }); }