From e6c35ac5a0324fe989ea531e51b32c5c3543a895 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 00:17:31 -0800 Subject: [PATCH 1/7] fix: prisma int supports up to 2gb. Bigint supports a lot more than 2gb. --- prisma/schema.prisma | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ed47f0036..8e25c5c94 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -48,7 +48,7 @@ model File { originalName String? mimetype String @default("image/png") createdAt DateTime @default(now()) - size Int @default(0) + size BigInt @default(0) expiresAt DateTime? maxViews Int? views Int @default(0) @@ -63,7 +63,7 @@ model File { folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull) folderId Int? - thumbnail Thumbnail? + thumbnail Thumbnail? } model Thumbnail { From 6f25167da56a1ceec8245c4d99dd17a8ad6e2ae5 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 00:29:16 -0800 Subject: [PATCH 2/7] yes, i ran `yarn migrate:dev` --- .../migrations/20231109082848_fix_large_uploads/migration.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 prisma/migrations/20231109082848_fix_large_uploads/migration.sql diff --git a/prisma/migrations/20231109082848_fix_large_uploads/migration.sql b/prisma/migrations/20231109082848_fix_large_uploads/migration.sql new file mode 100644 index 000000000..922215cf6 --- /dev/null +++ b/prisma/migrations/20231109082848_fix_large_uploads/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "File" ALTER COLUMN "size" SET DATA TYPE BIGINT; From 878e2897c7fa6e6b78f60bd2cbcca24076b3c26b Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 00:58:50 -0800 Subject: [PATCH 3/7] fix: cannot assign bigint to number --- src/pages/api/user/files.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/api/user/files.ts b/src/pages/api/user/files.ts index 2e2ac459a..2a0583690 100644 --- a/src/pages/api/user/files.ts +++ b/src/pages/api/user/files.ts @@ -139,7 +139,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) { expiresAt: Date; maxViews: number; views: number; - size: number; + size: bigint; originalName: string; thumbnail?: { name: string }; }[] = await prisma.file.findMany({ From 033dd0425c8fbd79325485bf3727357425d17dbd Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 01:09:37 -0800 Subject: [PATCH 4/7] fix: 'bigint' is not assignable to type 'number'. --- src/pages/api/user/paged.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/api/user/paged.ts b/src/pages/api/user/paged.ts index 84eb9abcd..fbe5093a6 100644 --- a/src/pages/api/user/paged.ts +++ b/src/pages/api/user/paged.ts @@ -83,7 +83,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) { maxViews: number; views: number; folderId: number; - size: number; + size: bigint; password: string | boolean; thumbnail?: { name: string }; }[] = await prisma.file.findMany({ From c1bf0cf79db57c5678dabc70e61786fc8a0a7090 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 01:09:37 -0800 Subject: [PATCH 5/7] fix: 'bigint' is not assignable to type 'number'. --- src/pages/api/user/paged.ts | 2 +- src/pages/folder/[id].tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/api/user/paged.ts b/src/pages/api/user/paged.ts index 84eb9abcd..fbe5093a6 100644 --- a/src/pages/api/user/paged.ts +++ b/src/pages/api/user/paged.ts @@ -83,7 +83,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) { maxViews: number; views: number; folderId: number; - size: number; + size: bigint; password: string | boolean; thumbnail?: { name: string }; }[] = await prisma.file.findMany({ diff --git a/src/pages/folder/[id].tsx b/src/pages/folder/[id].tsx index b0d56d777..6dfa33455 100644 --- a/src/pages/folder/[id].tsx +++ b/src/pages/folder/[id].tsx @@ -12,7 +12,7 @@ type LimitedFolder = { createdAt: Date | string; mimetype: string; views: number; - size: number; + size: bigint; }[]; user: { username: string; From 262f09533d23d05bd24539a0da63301daa03556b Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 01:59:37 -0800 Subject: [PATCH 6/7] jesus christ --- src/server/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/index.ts b/src/server/index.ts index 9f268dcc6..98ea0a4e8 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -28,6 +28,12 @@ const logger = Logger.get('server'); const server = fastify(genFastifyOpts()); +// Normally I would never condone this, but I lack the patience to deal with this correctly. +// This is just to get JSON.stringify to globally serialize BigInt's +BigInt.prototype['toJSON'] = function () { + return this.toString(); +}; + if (dev) { server.addHook('onRoute', (opts) => { logger.child('route').debug(JSON.stringify(opts)); From 6b428030c3059d16ceec2af3c1988bbe86c1fc47 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 9 Nov 2023 02:49:08 -0800 Subject: [PATCH 7/7] Well okay then next --- src/server/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/index.ts b/src/server/index.ts index 98ea0a4e8..9418b9629 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -31,7 +31,7 @@ const server = fastify(genFastifyOpts()); // Normally I would never condone this, but I lack the patience to deal with this correctly. // This is just to get JSON.stringify to globally serialize BigInt's BigInt.prototype['toJSON'] = function () { - return this.toString(); + return Number(this); }; if (dev) {