Files
caddy-proxy-manager/app/api/analytics/blocked/route.ts
fuomag9 9e2007eb0c feat: add custom date range picker, fix country click highlight on map
- Analytics default interval changed to 1h
- Add 'Custom' toggle option with datetime-local pickers (pre-filled to last 24h)
- Refactor analytics-db: buildWhere now takes from/to unix timestamps instead of Interval
- Export INTERVAL_SECONDS from analytics-db for route reuse
- All 6 API routes accept from/to params (fallback to interval if absent)
- Timeline bucket size computed from duration rather than hardcoded per interval
- Fix map country click highlight: bake isSelected into GeoJSON features (data-driven)
  instead of relying on Layer filter prop updates (unreliable in react-map-gl v8)
- Split highlight into countries-selected (data-driven) and countries-hover (filter-driven)
- Show tooltip at country centroid when selected via table, hover takes precedence

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 10:38:02 +01:00

26 lines
1.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { requireUser } from '@/src/lib/auth';
import { getAnalyticsBlocked, INTERVAL_SECONDS } from '@/src/lib/analytics-db';
export async function GET(req: NextRequest) {
await requireUser();
const { searchParams } = req.nextUrl;
const host = searchParams.get('host') ?? 'all';
const page = parseInt(searchParams.get('page') ?? '1', 10);
const { from, to } = resolveRange(searchParams);
const data = await getAnalyticsBlocked(from, to, host, page);
return NextResponse.json(data);
}
function resolveRange(params: URLSearchParams): { from: number; to: number } {
const fromParam = params.get('from');
const toParam = params.get('to');
if (fromParam && toParam) {
return { from: parseInt(fromParam, 10), to: parseInt(toParam, 10) };
}
const interval = params.get('interval') ?? '1h';
const to = Math.floor(Date.now() / 1000);
const from = to - (INTERVAL_SECONDS[interval as keyof typeof INTERVAL_SECONDS] ?? INTERVAL_SECONDS['1h']);
return { from, to };
}