import { ImageResponse } from 'next/og'; import type { NextRequest } from 'next/server'; import { Wallpaper } from '@/components/brand/og'; import { daysBefore, ISO_DAY, todayUtc } from '@/components/temporal/dates'; import { apiD3, safe } from '@/lib/api'; import { fmtDate, fmtInt, num } from '@/lib/format'; export const runtime = 'nodejs'; export const revalidate = 1800; /** Dynamic OG image for /diff?a=&b=&scope= โ€” both dates and the live counts. */ export async function GET(req: NextRequest): Promise { const sp = req.nextUrl.searchParams; const b = ISO_DAY.test(sp.get('b') ?? '') ? (sp.get('b') as string) : todayUtc(); const a = ISO_DAY.test(sp.get('a') ?? '') ? (sp.get('a') as string) : daysBefore(b, 7); const scope = sp.get('scope') || 'all'; const d = a < b ? await safe(apiD3.diff(a, b, scope, 1)) : null; const c = d?.counts ?? {}; const n = (k: string) => fmtInt(num(c[k])); const counters: [string, string][] = d ? [['New entities', n('new_entities')], ['Price changes', n('price_changes')], ['Context', n('context_changes')], ['New leaders', n('new_benchmark_leaders')], ['Events', n('events')]] : []; return new ImageResponse(, { width: 1200, height: 630 }); }