Skip to content

Commit

Permalink
Made upload size configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski committed Sep 24, 2024
1 parent e740944 commit bf03844
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const Config = z.object({
OTHER_NO_LOGO: v.boolean(),
OTHER_HARD_RESET_PAGE: v.boolean(),
OTHER_BROWSER_SHELL_MODE: v.boolean(),
OTHER_UPLOAD_SIZE_LIMIT: v.positiveNum(),

// debugger
DEBUG_ENABLE: v.boolean(),
Expand Down
7 changes: 7 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,13 @@ export const defaultConfig = {
type: 'boolean',
envLink: 'OTHER_BROWSER_SHELL_MODE',
description: 'Decides if the browser runs in the shell mode.'
},
uploadSizeLimit: {
value: 50 * 1024 * 1024,
type: 'number',
envLink: 'OTHER_UPLOAD_SIZE_LIMIT',
description:
'The maximum size of the uploaded file in bytes. The default is 50 MB (50 * 1024 * 1024 bytes).'
}
},
debug: {
Expand Down
36 changes: 20 additions & 16 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import errorHandler from './error.js';
import rateLimit from './rate_limit.js';
import { log, logWithStack } from '../logger.js';
import { __dirname } from '../utils.js';
import { getOptions } from '../config.js';

import vSwitchRoute from './routes/change_hc_version.js';
import exportRoutes from './routes/export.js';
Expand All @@ -45,22 +46,6 @@ app.disable('x-powered-by');
// Enable CORS support
app.use(cors());

// Enable parsing of form data (files) with Multer package
const storage = multer.memoryStorage();
const upload = multer({
storage,
limits: {
fieldSize: 50 * 1024 * 1024
}
});

// Enable body parser
app.use(express.json({ limit: 50 * 1024 * 1024 }));
app.use(express.urlencoded({ extended: true, limit: 50 * 1024 * 1024 }));

// Use only non-file multipart form fields
app.use(upload.none());

/**
* Attach error handlers to the server.
*
Expand Down Expand Up @@ -93,6 +78,25 @@ const attachServerErrorHandlers = (server) => {
* and started.
*/
export const startServer = async (serverConfig) => {
const uploadSizeLimit =
getOptions()?.other?.uploadSizeLimit || 50 * 1024 * 1024;

// Enable parsing of form data (files) with Multer package
const storage = multer.memoryStorage();
const upload = multer({
storage,
limits: {
fieldSize: uploadSizeLimit
}
});

// Enable body parser
app.use(express.json({ limit: uploadSizeLimit }));
app.use(express.urlencoded({ extended: true, limit: uploadSizeLimit }));

// Use only non-file multipart form fields
app.use(upload.none());

try {
// Stop if not enabled
if (!serverConfig.enable) {
Expand Down

0 comments on commit bf03844

Please sign in to comment.