- 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>
25 lines
984 B
TypeScript
25 lines
984 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { requireUser } from '@/src/lib/auth';
|
|
import { getAnalyticsCountries, 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 { from, to } = resolveRange(searchParams);
|
|
const data = await getAnalyticsCountries(from, to, host);
|
|
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 };
|
|
}
|