From f4d4d6a773d5dd6b3c604d32f7a3aa6b46adb005 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 21 Nov 2024 22:07:16 +0500 Subject: [PATCH] feat: add new search endpoints to the search API --- app/api/search/route.ts | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index cba8644..ce7f73d 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -8,19 +8,44 @@ export async function GET(request: NextRequest) { const query = decodeURI(request.nextUrl.searchParams.get("q")) || null; const token = request.nextUrl.searchParams.get("token") || null; - const where = request.nextUrl.searchParams.get("where") || "releases" - const searchBy = parseInt(request.nextUrl.searchParams.get("searchBy")) || 0 - const list = parseInt(request.nextUrl.searchParams.get("list")) || null + const where = request.nextUrl.searchParams.get("where") || "releases"; + const searchBy = parseInt(request.nextUrl.searchParams.get("searchBy")) || 0; + const list = parseInt(request.nextUrl.searchParams.get("list")) || null; let url: URL; - if (where == "releases") { - url = new URL(`${ENDPOINTS.search}/releases/${page}`); - } else if (where == "list") { - if (!list) { return NextResponse.json({ message: "List ID required" }, { status: 400 })} - if (!token) { return NextResponse.json({ message: "token required" }, { status: 400 })} + if (where == "list") { + if (!list) { + return NextResponse.json( + { message: "List ID required" }, + { status: 400 } + ); + } + if (!token) { + return NextResponse.json({ message: "token required" }, { status: 400 }); + } url = new URL(`${ENDPOINTS.search}/profile/list/${list}/${page}`); + } else if (where == "history") { + if (!token) { + return NextResponse.json({ message: "token required" }, { status: 400 }); + } + url = new URL(`${ENDPOINTS.search}/history/${page}`); + } else if (where == "favorites") { + if (!token) { + return NextResponse.json({ message: "token required" }, { status: 400 }); + } + url = new URL(`${ENDPOINTS.search}/favorites/${page}`); + } else if (where == "collections") { + if (!token) { + return NextResponse.json({ message: "token required" }, { status: 400 }); + } + url = new URL(`${ENDPOINTS.search}/favoriteCollections/${page}`); + } else if (where == "profiles") { + url = new URL(`${ENDPOINTS.search}/profiles/${page}`); + } else { + url = new URL(`${ENDPOINTS.search}/releases/${page}`); } + if (token) { url.searchParams.set("token", token); }