From a853f6941ee2c8692574218790c2e5bc38346505 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 21 Oct 2024 10:29:09 +0000 Subject: [PATCH] fix: limit number of files --- packages/nocodb/src/constants/index.ts | 4 ++++ packages/nocodb/src/modules/noco.module.ts | 9 +++++++-- packages/nocodb/src/services/utils.service.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/constants/index.ts b/packages/nocodb/src/constants/index.ts index c2fdcb32cf..0016f24fd8 100644 --- a/packages/nocodb/src/constants/index.ts +++ b/packages/nocodb/src/constants/index.ts @@ -1,4 +1,8 @@ export const NC_LICENSE_KEY = 'nc-license-key'; export const NC_APP_SETTINGS = 'nc-app-settings'; +export const NC_NON_ATTACHMENT_FIELD_SIZE = + +process.env['NC_NON_ATTACHMENT_FIELD_SIZE'] || 10 * 1024 * 1024; // 10 MB export const NC_ATTACHMENT_FIELD_SIZE = +process.env['NC_ATTACHMENT_FIELD_SIZE'] || 20 * 1024 * 1024; // 20 MB +export const NC_MAX_ATTACHMENTS_ALLOWED = + +process.env['NC_MAX_ATTACHMENTS_ALLOWED'] || 10; diff --git a/packages/nocodb/src/modules/noco.module.ts b/packages/nocodb/src/modules/noco.module.ts index 51e384a541..164272f51b 100644 --- a/packages/nocodb/src/modules/noco.module.ts +++ b/packages/nocodb/src/modules/noco.module.ts @@ -22,7 +22,11 @@ import { UsersController } from '~/controllers/users/users.controller'; import { UsersService } from '~/services/users/users.service'; /* Metas */ -import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; +import { + NC_ATTACHMENT_FIELD_SIZE, + NC_MAX_ATTACHMENTS_ALLOWED, + NC_NON_ATTACHMENT_FIELD_SIZE, +} from '~/constants'; import { MetaService } from '~/meta/meta.service'; import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller'; import { ApiTokensController } from '~/controllers/api-tokens.controller'; @@ -132,8 +136,9 @@ export const nocoModuleMetadata = { MulterModule.register({ storage: multer.diskStorage({}), limits: { - fieldSize: NC_ATTACHMENT_FIELD_SIZE, + fieldSize: NC_NON_ATTACHMENT_FIELD_SIZE, fileSize: NC_ATTACHMENT_FIELD_SIZE, + files: NC_MAX_ATTACHMENTS_ALLOWED, }, }), ], diff --git a/packages/nocodb/src/services/utils.service.ts b/packages/nocodb/src/services/utils.service.ts index 53072e0cb3..b4fb73bb47 100644 --- a/packages/nocodb/src/services/utils.service.ts +++ b/packages/nocodb/src/services/utils.service.ts @@ -8,7 +8,11 @@ import { useAgent } from 'request-filtering-agent'; import dayjs from 'dayjs'; import type { ErrorReportReqType } from 'nocodb-sdk'; import type { AppConfig, NcRequest } from '~/interface/config'; -import { NC_APP_SETTINGS, NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; +import { + NC_APP_SETTINGS, + NC_ATTACHMENT_FIELD_SIZE, + NC_MAX_ATTACHMENTS_ALLOWED, +} from '~/constants'; import SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2'; import { NcError } from '~/helpers/catchError'; import { Base, Store, User } from '~/models'; @@ -465,7 +469,7 @@ export class UtilsService { ncSiteUrl: (param.req as any).ncSiteUrl, ee: Noco.isEE(), ncAttachmentFieldSize: NC_ATTACHMENT_FIELD_SIZE, - ncMaxAttachmentsAllowed: +(process.env.NC_MAX_ATTACHMENTS_ALLOWED || 10), + ncMaxAttachmentsAllowed: NC_MAX_ATTACHMENTS_ALLOWED, isCloud: process.env.NC_CLOUD === 'true', automationLogLevel: process.env.NC_AUTOMATION_LOG_LEVEL || 'OFF', baseHostName: process.env.NC_BASE_HOST_NAME,