From d5840e2ee7f69df5ccf7cfd43dee6d42405f6e66 Mon Sep 17 00:00:00 2001 From: Mansive <33560917+Mansive@users.noreply.github.com> Date: Sat, 6 Jan 2024 05:47:10 -0600 Subject: [PATCH] Reduce transfer size --- src/app/api/search/route.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/app/api/search/route.tsx b/src/app/api/search/route.tsx index a66edef..1aebbc8 100644 --- a/src/app/api/search/route.tsx +++ b/src/app/api/search/route.tsx @@ -16,11 +16,26 @@ export async function GET(request: NextRequest) { ); } - const results = await xata.db.Books.search(searchParams, { - target: ["title"], - fuzziness: 0, - page: { size: 50, offset: 0 }, - }); + try { + const results = await xata.db.Books.search(searchParams, { + target: ["title"], + fuzziness: 0, + page: { size: 50, offset: 0 }, + }); - return NextResponse.json(results); + // Pasted from Copilot; could probably be done better + const records = JSON.parse(JSON.stringify(results))["records"]; + records.forEach((book: Record) => { + delete book.id; + delete book.embeddings; + delete book.xata; + }); + + return NextResponse.json({ records }); + } catch (error) { + return NextResponse.json( + { message: "A strange error has ocurred" }, + { status: 500 } + ); + } }