From b79ebb6c07aa8bdbba571ae4254163a64bb0ee36 Mon Sep 17 00:00:00 2001 From: IrosTheBeggar Date: Tue, 22 Feb 2022 00:05:12 -0500 Subject: [PATCH] edit server max request size --- src/api/admin.js | 13 +++++++- src/server.js | 2 +- src/state/config.js | 1 + src/util/admin.js | 11 +++++++ webapp/admin/index.js | 75 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/api/admin.js b/src/api/admin.js index 87bbdfc..d0bdbec 100644 --- a/src/api/admin.js +++ b/src/api/admin.js @@ -291,10 +291,21 @@ exports.setup = (mstream) => { writeLogs: config.program.writeLogs, secret: config.program.secret.slice(-4), ssl: config.program.ssl, - storage: config.program.storage + storage: config.program.storage, + maxRequestSize: config.program.maxRequestSize }); }); + mstream.post("/api/v1/admin/config/max-request-size", async (req, res) => { + const schema = Joi.object({ + maxRequestSize: Joi.string().pattern(/[0-9]+(KB|MB)/i).required() + }); + joiValidate(schema, req.body); + + await admin.editMaxRequestSize(req.body.maxRequestSize); + res.json({}); + }); + mstream.post("/api/v1/admin/config/port", async (req, res) => { const schema = Joi.object({ port: Joi.number().required() diff --git a/src/server.js b/src/server.js index 3261765..e6fbb07 100644 --- a/src/server.js +++ b/src/server.js @@ -64,7 +64,7 @@ exports.serveIt = async configFile => { // Magic Middleware Things mstream.use(cookieParser()); - mstream.use(express.json({limit: '1mb'})); + mstream.use(express.json({ limit: config.program.maxRequestSize })); mstream.use(express.urlencoded({ extended: true })); mstream.use((req, res, next) => { // CORS res.header("Access-Control-Allow-Origin", "*"); diff --git a/src/state/config.js b/src/state/config.js index 03d49b4..2a0131a 100644 --- a/src/state/config.js +++ b/src/state/config.js @@ -73,6 +73,7 @@ const schema = Joi.object({ rpn: rpnOptions.default(rpnOptions.validate({}).value), transcode: transcodeOptions.default(transcodeOptions.validate({}).value), secret: Joi.string().optional(), + maxRequestSize: Joi.string().pattern(/[0-9]+(KB|MB)/i).default('1MB'), db: dbOptions.default(dbOptions.validate({}).value), folders: Joi.object().pattern( Joi.string(), diff --git a/src/util/admin.js b/src/util/admin.js index 48d5ae5..ad35717 100644 --- a/src/util/admin.js +++ b/src/util/admin.js @@ -187,6 +187,17 @@ exports.editPort = async (port) => { mStreamServer.reboot(); } +exports.editMaxRequestSize = async (maxRequestSize) => { + if (config.program.maxRequestSize === maxRequestSize) { return; } + + const loadConfig = await this.loadFile(config.configFile); + loadConfig.maxRequestSize = maxRequestSize; + await this.saveFile(loadConfig, config.configFile); + + // reboot server + mStreamServer.reboot(); +} + exports.editUpload = async (val) => { const loadConfig = await this.loadFile(config.configFile); loadConfig.noUpload = val; diff --git a/webapp/admin/index.js b/webapp/admin/index.js index 38f3727..4aaaf78 100644 --- a/webapp/admin/index.js +++ b/webapp/admin/index.js @@ -696,6 +696,12 @@ const advancedView = Vue.component('advanced-view', { [edit] + + Max Request Size: {{params.maxRequestSize}} + + [edit] + + Address: {{params.address}} @@ -2473,6 +2479,74 @@ const userAccessView = Vue.component('user-access-view', { } }); +const editRequestSizeModal = Vue.component('edit-request-size-modal', { + data() { + return { + params: ADMINDATA.serverParams, + submitPending: false, + maxRequestSize: ADMINDATA.serverParams.maxRequestSize + }; + }, + template: ` +
+ + +
`, + mounted: function () { + M.updateTextFields(); + }, + methods: { + updatePort: async function() { + try { + this.submitPending = true; + this.maxRequestSize = this.maxRequestSize.replaceAll(' ', ''); + + await API.axios({ + method: 'POST', + url: `${API.url()}/api/v1/admin/config/max-request-size`, + data: { maxRequestSize: this.maxRequestSize } + }); + + // update fronted data + Vue.set(ADMINDATA.serverParams, 'maxRequestSize', this.maxRequestSize); + + // close & reset the modal + M.Modal.getInstance(document.getElementById('admin-modal')).close(); + + iziToast.success({ + title: 'Success: Allow the server 30 seconds to reboot', + position: 'topCenter', + timeout: 3500 + }); + } catch(err) { + iziToast.error({ + title: 'Failed to Update', + position: 'topCenter', + timeout: 3500 + }); + }finally { + this.submitPending = false; + } + } + } +}); + + const editPortModal = Vue.component('edit-port-modal', { data() { return { @@ -3316,6 +3390,7 @@ const modVM = new Vue({ 'user-access-modal': userAccessView, 'file-explorer-modal': fileExplorerModal, 'edit-port-modal': editPortModal, + 'edit-request-size-modal': editRequestSizeModal, 'edit-address-modal': editAddressModal, 'edit-scan-interval-modal': editScanIntervalView, 'edit-save-interval-modal': editSaveIntervalView,