From 27f9f7ac64911893db2199bee6c1651597493eb7 Mon Sep 17 00:00:00 2001 From: twotalesanimation <80506065+twotalesanimation@users.noreply.github.com> Date: Tue, 22 Sep 2026 17:23:03 +0200 Subject: [PATCH] fix(api): shot API 500 once a version has a ProRes size Version.highResSize (added in 9660cdc) is a BigInt, and GET /api/shots/[shotId] spreads whole version rows into NextResponse.json, converting only fileSize. As soon as worker 1.7.0 finalized an export with a ProRes upload, JSON.stringify threw "Do not know how to serialize a BigInt" and the shot page failed to load. - Convert highResSize alongside fileSize in that route. - lib/db.ts: serialize any BigInt as a string in JSON (BigInt.prototype .toJSON), so other routes returning whole rows can't 500 the same way. Co-Authored-By: Claude Opus 5 --- app/api/shots/[shotId]/route.ts | 3 ++- lib/db.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/api/shots/[shotId]/route.ts b/app/api/shots/[shotId]/route.ts index d0b0f5d..b69a076 100644 --- a/app/api/shots/[shotId]/route.ts +++ b/app/api/shots/[shotId]/route.ts @@ -82,7 +82,7 @@ export async function GET( session.user.role as string ); - // Serialize BigInt fields (fileSize) so JSON.stringify doesn't throw + // Serialize BigInt fields (fileSize, highResSize) so JSON.stringify doesn't throw const shotSerialized = { ...shot, footagePlates: shot.footagePlates.map((p) => ({ @@ -92,6 +92,7 @@ export async function GET( versions: shot.versions.map((v) => ({ ...v, fileSize: v.fileSize != null ? v.fileSize.toString() : null, + highResSize: v.highResSize != null ? v.highResSize.toString() : null, })), }; diff --git a/lib/db.ts b/lib/db.ts index 9bb9ce6..7752e14 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -1,5 +1,25 @@ import { PrismaClient } from "@prisma/client"; +// Safety net: Prisma returns BigInt columns (fileSize, highResSize, …) as +// BigInt, which JSON.stringify refuses — one such column anywhere in an API +// response turns the whole route into a 500. Serialize them as strings, the +// same shape the routes that convert them by hand already produce. Routes +// that spread whole rows into NextResponse.json are then safe by default. +declare global { + interface BigInt { + toJSON(): string; + } +} +if (!("toJSON" in BigInt.prototype)) { + Object.defineProperty(BigInt.prototype, "toJSON", { + value: function toJSON(this: bigint) { + return this.toString(); + }, + writable: true, + configurable: true, + }); +} + const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined; };