feat(search): migrate to backend endpoint

This commit is contained in:
zetaloop
2026-02-28 12:17:52 +08:00
parent db02313801
commit 8463e9ea1c
3 changed files with 18 additions and 124 deletions
-62
View File
@@ -1,62 +0,0 @@
import { mockPlayers, mockServices, mockShops } from "@/lib/mock"
import { searchCatalog } from "@/lib/search/search-catalog"
import type { SearchSort } from "@/lib/search/types"
import { NextResponse } from "next/server"
export const dynamic = "force-dynamic"
const SEARCH_SORTS: ReadonlySet<SearchSort> = new Set([
"composite",
"rating",
"orders",
"price_asc",
"price_desc",
])
function numberParam(value: string | null, fallback: number) {
if (value === null) return fallback
const parsed = Number(value)
return Number.isFinite(parsed) ? parsed : fallback
}
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const q = searchParams.get("q") ?? undefined
const selectedGames = searchParams.getAll("game")
const min = searchParams.get("min") ?? ""
const max = searchParams.get("max") ?? ""
const onlyOnline = (searchParams.get("online") ?? "0") === "1"
const minRating = searchParams.get("minRating") ?? "0"
const sortParam = (searchParams.get("sort") ?? "composite") as SearchSort
const sort: SearchSort = SEARCH_SORTS.has(sortParam) ? sortParam : "composite"
const limit = numberParam(searchParams.get("limit"), 12)
const offset = numberParam(searchParams.get("offset"), 0)
const response = searchCatalog(
{
q,
selectedGames,
min,
max,
onlyOnline,
minRating,
sort,
limit,
offset,
},
{
players: mockPlayers,
shops: mockShops,
services: mockServices,
},
)
return NextResponse.json(response, {
headers: {
"Cache-Control": "no-store",
},
})
}