From c00fc528ac821693ef24154c99766e1c7fb4ba2f Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 22 Mar 2026 09:56:10 +0100 Subject: [PATCH] fix: BigInt literal compatibility and bot link code JSON parsing - Replace 0n literals with BigInt(0) for ES2017 target compatibility - Parse link code JSON to extract userId and check expiration (was passing raw JSON string as FK, causing constraint violation) Co-Authored-By: Claude Opus 4.6 (1M context) --- bot/src/db/queries.ts | 11 ++++++++++- src/app/(app)/stls/actions.ts | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bot/src/db/queries.ts b/bot/src/db/queries.ts index 1bd2cd8..12a3969 100644 --- a/bot/src/db/queries.ts +++ b/bot/src/db/queries.ts @@ -21,7 +21,16 @@ export async function findLinkByUserId(userId: string) { export async function validateLinkCode(code: string): Promise { const key = `link_code:${code}`; const setting = await db.globalSetting.findUnique({ where: { key } }); - return setting?.value ?? null; + if (!setting) return null; + + try { + const parsed = JSON.parse(setting.value); + if (parsed.expiresAt && new Date(parsed.expiresAt) < new Date()) return null; + return parsed.userId ?? null; + } catch { + // Legacy format: value is the userId directly + return setting.value; + } } export async function deleteLinkCode(code: string): Promise { diff --git a/src/app/(app)/stls/actions.ts b/src/app/(app)/stls/actions.ts index 0e1835c..9693355 100644 --- a/src/app/(app)/stls/actions.ts +++ b/src/app/(app)/stls/actions.ts @@ -60,7 +60,7 @@ export async function uploadPackagePreview( data: { previewData: buffer, // Set previewMsgId to 0 as sentinel so hasPreview checks work - previewMsgId: 0n, + previewMsgId: BigInt(0), }, }); @@ -125,7 +125,7 @@ export async function setPreviewFromExtract( previewData: extractReq.imageData, // Set previewMsgId to 0 as sentinel so hasPreview checks work // (original Telegram-matched previews have the actual message ID) - previewMsgId: 0n, + previewMsgId: BigInt(0), }, });