lint compliance and some notes

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

@ -176,6 +176,7 @@ var restoreArchivedDocument = function (Env, Server, cb) {
};
// CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_DEFAULT_STORAGE_LIMIT', 1024 * 1024 * 1024 /* 1GB */], console.log)
// XXX remove
var setDefaultStorageLimit = function (Env, Server, cb, data) {
var value = Array.isArray(data) && data[1];
if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); }

@ -7,14 +7,23 @@ const Keys = require("../keys");
const Package = require('../../package.json');
const Https = require("https");
Quota.applyCustomLimits = function (Env) {
var isLimit = function (o) {
Quota.isValidLimit = function (o) {
var valid = o && typeof(o) === 'object' &&
typeof(o.limit) === 'number' &&
typeof(o.plan) === 'string' &&
typeof(o.note) === 'string';
typeof(o.note) === 'string' &&
// optionally contains a 'users' array
(Array.isArray(o.users) || typeof(o.users) === 'undefined');
return valid;
};
};
Quota.applyCustomLimits = function (Env) {
// DecreedLimits > customLimits > serverLimits;
// XXX perform an integrity check on shared limits
// especially relevant because we use Env.limits
// when considering whether to archive inactive accounts
// read custom limits from the Environment (taken from config)
var customLimits = (function (custom) {
@ -38,12 +47,12 @@ Quota.applyCustomLimits = function (Env) {
Env.limits = Env.limits || {};
Object.keys(customLimits).forEach(function (k) {
if (!isLimit(customLimits[k])) { return; }
if (!Quota.isValidLimit(customLimits[k])) { return; }
Env.limits[k] = customLimits[k];
});
// console.log(Env.limits);
};
/*
Env = {
myDomain,
@ -93,6 +102,9 @@ Quota.updateCachedLimits = function (Env, cb) {
response.on('end', function () {
try {
var json = JSON.parse(str);
// don't overwrite the limits with junk data
if (json && json.message === 'EINVAL') { return void cb(); }
Env.limits = json;
Quota.applyCustomLimits(Env);
//console.log('Env.customLimits', Env.customLimits);

@ -4,18 +4,30 @@ var Decrees = module.exports;
IMPLEMENTED:
RESTRICT_REGISTRATION
UPDATE_DEFAULT_STORAGE
RESTRICT_REGISTRATION(<boolean>)
UPDATE_DEFAULT_STORAGE(<number>)
NOT IMPLEMENTED:
// QUOTA MANAGEMENT
ADD_QUOTA
RM_QUOTA
RM_QUOTA(<string: unsafekey>)
UPDATE_QUOTA
// RESTRICTED REGISTRATION
ADD_INVITE
REVOKE_INVITE
REDEEM_INVITE
// 2.0
UPDATE_INACTIVE_TIME
UPDATE_ACCOUNT_RETENTION_TIME
UPDATE_ARCHIVE_RETENTION_TIME
// 3.0
UPDATE_MAX_UPLOAD_SIZE
UPDATE_PREMIUM_UPLOAD_SIZE
*/
var commands = {};
@ -44,9 +56,13 @@ commands.RESTRICT_REGISTRATION = function (Env, args) {
return true;
};
var isNonNegativeNumber = function (n) {
return !(typeof(n) !== 'number' || isNaN(n) || n < 0);
};
// 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) {
if (!Array.isArray(args) || isNonNegativeNumber(args[0])) {
throw new Error('INVALID_ARGS');
}
var limit = args[0];
@ -55,6 +71,23 @@ commands.UPDATE_DEFAULT_STORAGE = function (Env, args) {
return true;
};
//var Quota = require("./commands/quota");
commands.ADD_QUOTA = function (Env, args) {
args = args;
throw new Error("NOT_IMPLEMENTED");
};
commands.RM_QUOTA = function (Env, args) {
args = args;
throw new Error("NOT_IMPLEMENTED");
};
commands.UPDATE_QUOTA = function (Env, args) {
args = args;
throw new Error("NOT_IMPLEMENTED");
};
// [<command>, <args>, <author>, <time>]
var handleCommand = Decrees.handleCommand = function (Env, line) {
var command = line[0];
@ -111,8 +144,7 @@ var Schedule = require("./schedule");
Decrees.load = function (Env, cb) {
Env.scheduleDecree = Env.scheduleDecree || Schedule();
var decreePath = Env.paths.decree;
var decreeName = Path.join(Env.paths.decree, 'decree.ndjson');
var decreeName = Path.join(Env.paths.decree, 'decree.ndjson'); // XXX mkdirp
var stream = Fs.createReadStream(decreeName, {start: 0});

Loading…
Cancel
Save