From b2fcde87d84efeb2249737c18ce0ac0d46291fb1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 17 Mar 2020 10:11:52 -0400 Subject: [PATCH] implement an admin command to update the default storage limit without a restart --- lib/commands/admin-rpc.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 7b4334c24..a7cb59798 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -110,6 +110,23 @@ var flushCache = function (Env, Server, cb) { cb(void 0, true); }; + +// CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_DEFAULT_STORAGE_LIMIT', 1024 * 1024 * 1024 /* 1GB */], console.log) +var setDefaultStorageLimit = function (Env, Server, cb, data) { + var value = Array.isArray(data) && data[1]; + if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); } + var previous = Env.defaultStorageLimit; + var change = { + previous: previous, + current: value, + }; + + Env.defaultStorageLimit = value; + Env.Log.info('DEFAULT_STORAGE_LIMIT_UPDATE', change); + + cb(void 0, change); +}; + var commands = { ACTIVE_SESSIONS: getActiveSessions, ACTIVE_PADS: getActiveChannelCount, @@ -119,6 +136,7 @@ var commands = { SHUTDOWN: shutdown, GET_FILE_DESCRIPTOR_COUNT: getFileDescriptorCount, GET_FILE_DESCRIPTOR_LIMIT: getFileDescriptorLimit, + SET_DEFAULT_STORAGE_LIMIT: setDefaultStorageLimit, }; Admin.command = function (Env, safeKey, data, _cb, Server) { @@ -133,7 +151,7 @@ Admin.command = function (Env, safeKey, data, _cb, Server) { var command = commands[data[0]]; if (typeof(command) === 'function') { - return void command(Env, Server, cb); + return void command(Env, Server, cb, data); } return void cb('UNHANDLED_ADMIN_COMMAND');