From 5d234732e20650a845317e3137673d9ba2ac02a5 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Wed, 30 Nov 2022 11:50:00 +0530 Subject: [PATCH] fix(test): Made defealt file field size limit to 250MB and is configurable using NC_FILE_FIELD_SIZE env variable --- packages/nocodb/src/lib/constants/index.ts | 3 +++ packages/nocodb/src/lib/meta/NcMetaMgr.ts | 4 ++++ packages/nocodb/src/lib/meta/NcMetaMgrv2.ts | 4 ++++ packages/nocodb/src/lib/meta/api/attachmentApis.ts | 4 ++++ packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/packages/nocodb/src/lib/constants/index.ts b/packages/nocodb/src/lib/constants/index.ts index e52388f60a..c1f86a9aaa 100644 --- a/packages/nocodb/src/lib/constants/index.ts +++ b/packages/nocodb/src/lib/constants/index.ts @@ -1,2 +1,5 @@ export const NC_LICENSE_KEY = 'nc-license-key'; export const NC_APP_SETTINGS = 'nc-app-settings'; +export const NC_FILE_FIELD_SIZE = process.env['NC_FILE_FIELD_SIZE'] + ? Number(process.env['NC_FILE_FIELD_SIZE']) + : 250 * 1024 * 1024; // 250 MB diff --git a/packages/nocodb/src/lib/meta/NcMetaMgr.ts b/packages/nocodb/src/lib/meta/NcMetaMgr.ts index 789279dde6..aa9089e763 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgr.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgr.ts @@ -41,6 +41,7 @@ import { defaultConnectionConfig } from '../utils/NcConfigFactory'; import xcMetaDiff from './handlers/xcMetaDiff'; import { UITypes } from 'nocodb-sdk'; import { Tele } from 'nc-help'; +import { NC_FILE_FIELD_SIZE } from '../constants'; const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10); const XC_PLUGIN_DET = 'XC_PLUGIN_DET'; @@ -132,6 +133,9 @@ export default class NcMetaMgr { storage: multer.diskStorage({ // dest: path.join(this.config.toolDir, 'uploads') }), + limits: { + fieldSize: NC_FILE_FIELD_SIZE, + }, }); // router.post(this.config.dashboardPath, upload.single('file')); router.post(this.config.dashboardPath, upload.any()); diff --git a/packages/nocodb/src/lib/meta/NcMetaMgrv2.ts b/packages/nocodb/src/lib/meta/NcMetaMgrv2.ts index 371b353427..9eecf5e7c4 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgrv2.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgrv2.ts @@ -11,6 +11,7 @@ import NcPluginMgr from '../v1-legacy/plugins/NcPluginMgr'; import NcMetaIO from './NcMetaIO'; import { defaultConnectionConfig } from '../utils/NcConfigFactory'; import ncCreateLookup from './handlersv2/ncCreateLookup'; +import { NC_FILE_FIELD_SIZE } from '../constants'; // import ncGetMeta from './handlersv2/ncGetMeta'; export default class NcMetaMgrv2 { @@ -71,6 +72,9 @@ export default class NcMetaMgrv2 { storage: multer.diskStorage({ // dest: path.join(this.config.toolDir, 'uploads') }), + limits: { + fieldSize: NC_FILE_FIELD_SIZE, + }, }); // router.post(this.config.dashboardPath, upload.single('file')); router.post(this.config.dashboardPath, upload.any()); diff --git a/packages/nocodb/src/lib/meta/api/attachmentApis.ts b/packages/nocodb/src/lib/meta/api/attachmentApis.ts index 8af6ebfa46..ab09138c5e 100644 --- a/packages/nocodb/src/lib/meta/api/attachmentApis.ts +++ b/packages/nocodb/src/lib/meta/api/attachmentApis.ts @@ -9,6 +9,7 @@ import { Tele } from 'nc-help'; import ncMetaAclMw from '../helpers/ncMetaAclMw'; import catchError from '../helpers/catchError'; import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; +import { NC_FILE_FIELD_SIZE } from '../../constants'; // const storageAdapter = new Local(); export async function upload(req: Request, res: Response) { @@ -151,6 +152,9 @@ router.post( '/api/v1/db/storage/upload', multer({ storage: multer.diskStorage({}), + limits: { + fieldSize: NC_FILE_FIELD_SIZE, + }, }).any(), ncMetaAclMw(upload, 'upload') ); diff --git a/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts b/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts index 90eaddeabf..8af1775d2f 100644 --- a/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts +++ b/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts @@ -18,6 +18,7 @@ import slash from 'slash'; import { sanitizeUrlPath } from '../attachmentApis'; import getAst from '../../../db/sql-data-mapper/lib/sql/helpers/getAst'; import { getColumnByIdOrName } from '../dataApis/helpers'; +import { NC_FILE_FIELD_SIZE } from '../../../constants'; export async function dataList(req: Request, res: Response) { try { @@ -451,6 +452,9 @@ router.post( '/api/v1/db/public/shared-view/:sharedViewUuid/rows', multer({ storage: multer.diskStorage({}), + limits: { + fieldSize: NC_FILE_FIELD_SIZE, + }, }).any(), catchError(dataInsert) );