From 0bfbaea49aad0c695fee6558c89c661687912e4f Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 4 Apr 2024 20:54:21 +0200 Subject: [PATCH] feat: add config variable to adjust chunk size --- backend/prisma/seed/config.seed.ts | 5 +++++ backend/src/file/file.service.ts | 2 +- backend/src/main.ts | 10 +++++++++- frontend/src/i18n/translations/en-US.ts | 4 +++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/prisma/seed/config.seed.ts b/backend/prisma/seed/config.seed.ts index 8216329..d2fab1d 100644 --- a/backend/prisma/seed/config.seed.ts +++ b/backend/prisma/seed/config.seed.ts @@ -51,6 +51,11 @@ const configVariables: ConfigVariables = { type: "number", defaultValue: "9", }, + chunkSize: { + type: "number", + defaultValue: "10000000", + secret: false, + }, }, email: { enableShareEmailRecipients: { diff --git a/backend/src/file/file.service.ts b/backend/src/file/file.service.ts index b427584..ce9958d 100644 --- a/backend/src/file/file.service.ts +++ b/backend/src/file/file.service.ts @@ -47,7 +47,7 @@ export class FileService { } // If the sent chunk index and the expected chunk index doesn't match throw an error - const chunkSize = 10 * 1024 * 1024; // 10MB + const chunkSize = this.config.get("share.chunkSize"); const expectedChunkIndex = Math.ceil(diskFileSize / chunkSize); if (expectedChunkIndex != chunk.index) diff --git a/backend/src/main.ts b/backend/src/main.ts index d019c07..6e4f754 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -7,13 +7,21 @@ import * as cookieParser from "cookie-parser"; import * as fs from "fs"; import { AppModule } from "./app.module"; import { DATA_DIRECTORY } from "./constants"; +import { ConfigService } from "./config/config.service"; async function bootstrap() { const app = await NestFactory.create(AppModule); app.useGlobalPipes(new ValidationPipe({ whitelist: true })); app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); - app.use(bodyParser.raw({ type: "application/octet-stream", limit: "20mb" })); + const config = app.get(ConfigService); + app.use( + bodyParser.raw({ + type: "application/octet-stream", + limit: `${config.get("share.chunkSize")}B`, + }), + ); + app.use(cookieParser()); app.set("trust proxy", true); diff --git a/frontend/src/i18n/translations/en-US.ts b/frontend/src/i18n/translations/en-US.ts index 41fa642..9047dcd 100644 --- a/frontend/src/i18n/translations/en-US.ts +++ b/frontend/src/i18n/translations/en-US.ts @@ -432,7 +432,9 @@ export default { "admin.config.share.zip-compression-level": "Zip compression level", "admin.config.share.zip-compression-level.description": "Adjust the level to balance between file size and compression speed. Valid values range from 0 to 9, with 0 being no compression and 9 being maximum compression. ", - + "admin.config.share.chunk-size": "Chunk size", + "admin.config.share.chunk-size.description": "Adjust the chunk size (in bytes) for your uploads to balance efficiency and reliability according to your internet connection. Smaller chunks can enhance success rates for unstable connections, while larger chunks speed up uploads for stable connections.", + "admin.config.smtp.enabled": "Enabled", "admin.config.smtp.enabled.description": "Whether SMTP is enabled. Only set this to true if you entered the host, port, email, user and password of your SMTP server.",