Browse Source

fix: limit number of files

pull/9690/head
Pranav C 1 month ago
parent
commit
a853f6941e
  1. 4
      packages/nocodb/src/constants/index.ts
  2. 9
      packages/nocodb/src/modules/noco.module.ts
  3. 8
      packages/nocodb/src/services/utils.service.ts

4
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;

9
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,
},
}),
],

8
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,

Loading…
Cancel
Save