From 92a7355ce346c039aad22d6a533dfcd25096c39c Mon Sep 17 00:00:00 2001 From: RaenonX Date: Mon, 24 Nov 2025 08:07:31 +0800 Subject: [PATCH 1/3] Fixed `/api/batch` request recreation failure --- src/app/api/batch/route.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/api/batch/route.ts b/src/app/api/batch/route.ts index 6feab06b..aae14c96 100644 --- a/src/app/api/batch/route.ts +++ b/src/app/api/batch/route.ts @@ -18,7 +18,20 @@ export async function POST(request: Request) { let index = 0; for (const data of body) { - const newRequest = new Request(request, { body: JSON.stringify(data) }); + // Recreate a fresh Request since `new Request(request)` will have the following error: + // > Cannot read private member #state from an object whose class did not declare it + + // Copy headers we received, ensure JSON content type, and avoid conflicting content-length + const headers = new Headers(request.headers); + headers.set('content-type', 'application/json'); + headers.delete('content-length'); + + const newRequest = new Request(request.url, { + method: 'POST', + headers, + body: JSON.stringify(data), + }); + const response = await send.POST(newRequest); if (!response.ok) { From 805bc57bbb7fedf87edbc4ede9ff04f6c8bef374 Mon Sep 17 00:00:00 2001 From: RaenonX Date: Mon, 24 Nov 2025 15:21:20 +0800 Subject: [PATCH 2/3] Added `browser` / `os` / `device` override in `payload` --- src/app/api/send/route.ts | 3 +++ src/lib/detect.ts | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/api/send/route.ts b/src/app/api/send/route.ts index 2c2085bf..6ef66f30 100644 --- a/src/app/api/send/route.ts +++ b/src/app/api/send/route.ts @@ -41,6 +41,9 @@ const schema = z.object({ userAgent: z.string().optional(), timestamp: z.coerce.number().int().optional(), id: z.string().optional(), + browser: z.string().optional(), + os: z.string().optional(), + device: z.string().optional(), }) .refine( data => { diff --git a/src/lib/detect.ts b/src/lib/detect.ts index c5528465..083203ed 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -114,9 +114,9 @@ export async function getClientInfo(request: Request, payload: Record Date: Mon, 24 Nov 2025 15:26:54 +0800 Subject: [PATCH 3/3] Updated `/api/batch` to return `cache` --- src/app/api/batch/route.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/api/batch/route.ts b/src/app/api/batch/route.ts index aae14c96..46e8b3c3 100644 --- a/src/app/api/batch/route.ts +++ b/src/app/api/batch/route.ts @@ -17,6 +17,7 @@ export async function POST(request: Request) { const errors = []; let index = 0; + let cache = null; for (const data of body) { // Recreate a fresh Request since `new Request(request)` will have the following error: // > Cannot read private member #state from an object whose class did not declare it @@ -33,9 +34,12 @@ export async function POST(request: Request) { }); const response = await send.POST(newRequest); + const responseJson = await response.json(); if (!response.ok) { - errors.push({ index, response: await response.json() }); + errors.push({ index, response: responseJson }); + } else { + cache ??= responseJson.cache; } index++; @@ -46,6 +50,7 @@ export async function POST(request: Request) { processed: body.length - errors.length, errors: errors.length, details: errors, + cache, }); } catch (e) { return serverError(e);