d317e8c758
WS1: pin all Docker stages to node:24.16.0-alpine; add engines node>=20. WS2: lib/redis.ts gains TTL-backed redisSet, redisDel, setTunnelActive (writes tunnel:active:<sub>=1/0 EX 30, TUNNEL_ACTIVE_TTL override, no-op without REDIS_URL); wired into tunnel active/delete/reassign routes. WS3: sortable columns, CSV export routes (token excluded), and bulk actions (self-account guard) across users/tunnels/audit admin tables.
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { 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';
|
|
import { setTunnelActive } from '@/lib/redis';
|
|
import { jsonNoStore } from '@/lib/admin/response';
|
|
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function DELETE(
|
|
_req: NextRequest,
|
|
{ params }: { params: { id: string } },
|
|
) {
|
|
const auth = await requireAdminApi();
|
|
if (!auth.ok) return auth.response;
|
|
|
|
const { id } = params;
|
|
if (!isUuid(id)) {
|
|
return jsonNoStore({ error: 'invalid tunnel id' }, { status: 400 });
|
|
}
|
|
|
|
const admin = getSupabaseAdmin();
|
|
const { data, error } = await admin
|
|
.from('tunnels')
|
|
.delete()
|
|
.eq('user_id', id)
|
|
.select('subdomain')
|
|
.maybeSingle<{ subdomain: string }>();
|
|
if (error) {
|
|
console.error('admin tunnel.delete failed', error);
|
|
return jsonNoStore({ error: 'internal error' }, { status: 500 });
|
|
}
|
|
if (!data) {
|
|
return jsonNoStore({ error: 'tunnel not found' }, { status: 404 });
|
|
}
|
|
|
|
// Best-effort live kill-switch: write "0" so any live connection on the
|
|
// freed subdomain drops within ~1s. No-op when REDIS_URL is unset.
|
|
const redisOk = await setTunnelActive(data.subdomain, false);
|
|
|
|
await logAdminAction(auth.user, {
|
|
action: 'tunnel.delete',
|
|
target_type: 'tunnel',
|
|
target_id: id,
|
|
details: { subdomain: data.subdomain, redis: redisOk },
|
|
});
|
|
|
|
return jsonNoStore({ ok: true });
|
|
}
|