Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow uploads of files bigger than 2GiB #484

Merged
merged 9 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "File" ALTER COLUMN "size" SET DATA TYPE BIGINT;
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -63,7 +63,7 @@ model File {
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
folderId Int?

thumbnail Thumbnail?
thumbnail Thumbnail?
}

model Thumbnail {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/user/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/user/paged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/folder/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type LimitedFolder = {
createdAt: Date | string;
mimetype: string;
views: number;
size: number;
size: bigint;
}[];
user: {
username: string;
Expand Down
6 changes: 6 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 Number(this);
};

if (dev) {
server.addHook('onRoute', (opts) => {
logger.child('route').debug(JSON.stringify(opts));
Expand Down