edit server max request size

This commit is contained in:
IrosTheBeggar 2022-02-22 00:05:12 -05:00
parent 47cf9e366a
commit b79ebb6c07
5 changed files with 100 additions and 2 deletions

View File

@ -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()

View File

@ -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", "*");

View File

@ -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(),

View File

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

View File

@ -696,6 +696,12 @@ const advancedView = Vue.component('advanced-view', {
[<a v-on:click="openModal('edit-port-modal')">edit</a>]
</td>
</tr>
<tr>
<td><b>Max Request Size:</b> {{params.maxRequestSize}}</td>
<td>
[<a v-on:click="openModal('edit-request-size-modal')">edit</a>]
</td>
</tr>
<tr>
<td><b>Address:</b> {{params.address}}</td>
<td>
@ -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: `
<form @submit.prevent="updatePort">
<div class="modal-content">
<h4>Change Max Request Size</h4>
<p>Accepts KB or MB</p>
<div class="input-field">
<input v-model="maxRequestSize" id="edit-max-request-size" required type="text">
<label for="edit-port">Edit Max Request Size</label>
</div>
<blockquote>
Requires a reboot.
</blockquote>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Go Back</a>
<button class="btn green waves-effect waves-light" type="submit" :disabled="submitPending === true">
{{submitPending === false ? 'Update' : 'Updating...'}}
</button>
</div>
</form>`,
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,