import { NextResponse } from 'next/server'; import { getCurrentUser } from '@/lib/auth/session'; import { searchAssets } from '@/lib/account/queries'; export const dynamic = 'force-dynamic'; export async function GET(req: Request) { if (!(await getCurrentUser())) return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); const url = new URL(req.url); const q = (url.searchParams.get('q') ?? '').slice(0, 120); const category = url.searchParams.get('category') ?? undefined; const hits = await searchAssets(q, 12, category); return NextResponse.json(hits.map((h) => ({ id: h.id, title: h.title, categorySlug: h.categorySlug, year: h.year, heroImageUrl: h.heroImageUrl, rivUsd: h.rivUsd })), { headers: { 'cache-control': 'private, max-age=30' } }); }