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) // 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 setDefaultStorageLimit = function (Env, Server, cb, data) {
var value = Array.isArray(data) && data[1]; var value = Array.isArray(data) && data[1];
if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); } if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); }

@ -7,14 +7,23 @@ const Keys = require("../keys");
const Package = require('../../package.json'); const Package = require('../../package.json');
const Https = require("https"); const Https = require("https");
Quota.applyCustomLimits = function (Env) { Quota.isValidLimit = function (o) {
var isLimit = function (o) {
var valid = o && typeof(o) === 'object' && var valid = o && typeof(o) === 'object' &&
typeof(o.limit) === 'number' && typeof(o.limit) === 'number' &&
typeof(o.plan) === 'string' && 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; 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) // read custom limits from the Environment (taken from config)
var customLimits = (function (custom) { var customLimits = (function (custom) {
@ -38,12 +47,12 @@ Quota.applyCustomLimits = function (Env) {
Env.limits = Env.limits || {}; Env.limits = Env.limits || {};
Object.keys(customLimits).forEach(function (k) { Object.keys(customLimits).forEach(function (k) {
if (!isLimit(customLimits[k])) { return; } if (!Quota.isValidLimit(customLimits[k])) { return; }
Env.limits[k] = customLimits[k]; Env.limits[k] = customLimits[k];
}); });
// console.log(Env.limits);
}; };
/* /*
Env = { Env = {
myDomain, myDomain,
@ -93,6 +102,9 @@ Quota.updateCachedLimits = function (Env, cb) {
response.on('end', function () { response.on('end', function () {
try { try {
var json = JSON.parse(str); var json = JSON.parse(str);
// don't overwrite the limits with junk data
if (json && json.message === 'EINVAL') { return void cb(); }
Env.limits = json; Env.limits = json;
Quota.applyCustomLimits(Env); Quota.applyCustomLimits(Env);
//console.log('Env.customLimits', Env.customLimits); //console.log('Env.customLimits', Env.customLimits);

@ -4,18 +4,30 @@ var Decrees = module.exports;
IMPLEMENTED: IMPLEMENTED:
RESTRICT_REGISTRATION RESTRICT_REGISTRATION(<boolean>)
UPDATE_DEFAULT_STORAGE UPDATE_DEFAULT_STORAGE(<number>)
NOT IMPLEMENTED: NOT IMPLEMENTED:
// QUOTA MANAGEMENT
ADD_QUOTA ADD_QUOTA
RM_QUOTA RM_QUOTA(<string: unsafekey>)
UPDATE_QUOTA UPDATE_QUOTA
// RESTRICTED REGISTRATION
ADD_INVITE ADD_INVITE
REVOKE_INVITE REVOKE_INVITE
REDEEM_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 = {}; var commands = {};
@ -44,9 +56,13 @@ commands.RESTRICT_REGISTRATION = function (Env, args) {
return true; 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) // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log)
commands.UPDATE_DEFAULT_STORAGE = function (Env, args) { 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'); throw new Error('INVALID_ARGS');
} }
var limit = args[0]; var limit = args[0];
@ -55,6 +71,23 @@ commands.UPDATE_DEFAULT_STORAGE = function (Env, args) {
return true; 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>] // [<command>, <args>, <author>, <time>]
var handleCommand = Decrees.handleCommand = function (Env, line) { var handleCommand = Decrees.handleCommand = function (Env, line) {
var command = line[0]; var command = line[0];
@ -111,8 +144,7 @@ var Schedule = require("./schedule");
Decrees.load = function (Env, cb) { Decrees.load = function (Env, cb) {
Env.scheduleDecree = Env.scheduleDecree || Schedule(); Env.scheduleDecree = Env.scheduleDecree || Schedule();
var decreePath = Env.paths.decree; var decreeName = Path.join(Env.paths.decree, 'decree.ndjson'); // XXX mkdirp
var decreeName = Path.join(Env.paths.decree, 'decree.ndjson');
var stream = Fs.createReadStream(decreeName, {start: 0}); var stream = Fs.createReadStream(decreeName, {start: 0});

Loading…
Cancel
Save