implement 'UPDATE_DEFAULT_STORAGE' as a decree

pull/1/head
ansuz 4 years ago
parent 7aa7d5978f
commit 1781ee2585

@ -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'); }

@ -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;
};
// [<command>, <args>, <author>, <time>]
var handleCommand = Decrees.handleCommand = function (Env, line) {
var command = line[0];
var args = line[1];
if (typeof(commands[command]) !== 'function') {
console.error(line);
throw new Error("DECREE_UNSUPPORTED_COMMAND");
}
@ -101,7 +112,7 @@ Decrees.load = function (Env, cb) {
Env.scheduleDecree = Env.scheduleDecree || Schedule();
var decreePath = Env.paths.decree;
var decreeName = Path.join(Env.paths.decree, 'decree.ndjson'); // XXX
var decreeName = Path.join(Env.paths.decree, 'decree.ndjson');
var stream = Fs.createReadStream(decreeName, {start: 0});

@ -62,12 +62,6 @@ module.exports.create = function (config, cb) {
netfluxUsers: {},
pinStore: undefined,
// XXX deprecated?
pinnedPads: {},
pinsLoaded: false,
pendingPinInquiries: {},
pendingUnpins: {},
pinWorkers: 5,
limits: {},
admins: [],
@ -310,11 +304,9 @@ module.exports.create = function (config, cb) {
});
}, 60 * 1000);
}).nThen(function () {
// XXX scan the decree log to update Env
var Decrees = require("./decrees");
Decrees.load(Env, function (err) {
console.log("DONE LOADING DECREES"); // XXX
if (err) {
console.error(err);
}

Loading…
Cancel
Save