From 1781ee2585723665878b556806ded192a621de65 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 2 Oct 2020 13:36:02 +0530 Subject: [PATCH] implement 'UPDATE_DEFAULT_STORAGE' as a decree --- lib/commands/admin-rpc.js | 2 -- lib/decrees.js | 17 ++++++++++++++--- lib/historyKeeper.js | 8 -------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 0e1a9a8e5..bbcbc0c30 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -176,8 +176,6 @@ var restoreArchivedDocument = function (Env, Server, cb) { }; // CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_DEFAULT_STORAGE_LIMIT', 1024 * 1024 * 1024 /* 1GB */], console.log) -// XXX make this a decree -// XXX expose this via the admin panel (with UI) var setDefaultStorageLimit = function (Env, Server, cb, data) { var value = Array.isArray(data) && data[1]; if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); } diff --git a/lib/decrees.js b/lib/decrees.js index 4c769179e..cecb9d837 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -5,6 +5,7 @@ var Decrees = module.exports; IMPLEMENTED: RESTRICT_REGISTRATION +UPDATE_DEFAULT_STORAGE NOT IMPLEMENTED: @@ -15,7 +16,6 @@ ADD_INVITE REVOKE_INVITE REDEEM_INVITE - */ var commands = {}; @@ -33,6 +33,7 @@ var commands = {}; */ // Toggles a simple boolean +// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['RESTRICT_REGISTRATION', [true]]], console.log) commands.RESTRICT_REGISTRATION = function (Env, args) { if (!Array.isArray(args) || typeof(args[0]) !== 'boolean') { throw new Error('INVALID_ARGS'); @@ -43,13 +44,23 @@ commands.RESTRICT_REGISTRATION = function (Env, args) { return true; }; +// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log) +commands.UPDATE_DEFAULT_STORAGE = function (Env, args) { + if (!Array.isArray(args) || typeof(args[0]) !== 'number' || isNaN(args[0]) || args[0] < 0) { + throw new Error('INVALID_ARGS'); + } + var limit = args[0]; + if (limit === Env.defaultStorageLimit) { return false; } + Env.defaultStorageLimit = limit; + return true; +}; + // [, , ,