implement RM_QUOTA decree
parent
af47b2cab1
commit
5029281a53
|
@ -7,12 +7,11 @@ IMPLEMENTED:
|
|||
RESTRICT_REGISTRATION(<boolean>)
|
||||
UPDATE_DEFAULT_STORAGE(<number>)
|
||||
|
||||
NOT IMPLEMENTED:
|
||||
|
||||
// QUOTA MANAGEMENT
|
||||
ADD_QUOTA
|
||||
RM_QUOTA(<string: unsafekey>)
|
||||
UPDATE_QUOTA
|
||||
SET_QUOTA(<string:signkey>, limit)
|
||||
RM_QUOTA(<string:signkey>)
|
||||
|
||||
NOT IMPLEMENTED:
|
||||
|
||||
// RESTRICTED REGISTRATION
|
||||
ADD_INVITE
|
||||
|
@ -73,24 +72,34 @@ commands.UPDATE_DEFAULT_STORAGE = function (Env, args) {
|
|||
|
||||
var Quota = require("./commands/quota");
|
||||
var Keys = require("./keys");
|
||||
var Util = require("./common-util");
|
||||
|
||||
// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['ADD_QUOTA', ['[user@box:3000/VzeS4vP1DF+tXGuq1i50DKYuBL+09Yqy8kGxoUKRzhA=]', { limit: 2 * 1024 * 1024 * 1024, plan: 'buddy', note: "you're welcome" } ] ] ], console.log)
|
||||
commands.ADD_QUOTA = function (Env, args) {
|
||||
var getCanonicalKey = function (input) {
|
||||
if (typeof(input) !== 'string') { return; }
|
||||
// key is already in simple form. ensure that it is an 'unsafeKey'
|
||||
if (input.length === 44) {
|
||||
return Util.unescapeKeyCharacters(input);
|
||||
}
|
||||
try {
|
||||
return Keys.parseUser(input).pubkey;
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_QUOTA', ['[user@box:3000/VzeS4vP1DF+tXGuq1i50DKYuBL+09Yqy8kGxoUKRzhA=]', { limit: 2 * 1024 * 1024 * 1024, plan: 'buddy', note: "you're welcome" } ] ] ], console.log)
|
||||
commands.SET_QUOTA = function (Env, args) {
|
||||
if (!Array.isArray(args) || args.length !== 2) {
|
||||
throw new Error("INVALID_ARGS");
|
||||
}
|
||||
|
||||
var publicSigningKey = args[0];
|
||||
// this might throw, but that's fine
|
||||
var user = Keys.parseUser(publicSigningKey);
|
||||
if (!user || !user.pubkey || user.pubkey.length !== 44) {
|
||||
var unsafeKey = getCanonicalKey(args[0]);
|
||||
if (!unsafeKey) {
|
||||
throw new Error("INVALID_ARGS");
|
||||
}
|
||||
|
||||
// make sure you're not overwriting an existing limit
|
||||
if (Env.customLimits[user.pubkey]) {
|
||||
throw new Error("EEXISTS");
|
||||
}
|
||||
//if (Env.customLimits[unsafeKey]) { throw new Error("EEXISTS"); }
|
||||
|
||||
var limit = args[1];
|
||||
if (!Quota.isValidLimit(limit)) { // do we really want this?
|
||||
|
@ -98,20 +107,28 @@ commands.ADD_QUOTA = function (Env, args) {
|
|||
}
|
||||
|
||||
// map the new limit to the user's unsafeKey
|
||||
Env.customLimits[user.pubkey] = limit;
|
||||
Env.limits[user.pubkey] = limit;
|
||||
Env.customLimits[unsafeKey] = limit;
|
||||
Env.limits[unsafeKey] = limit;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
commands.RM_QUOTA = function (Env, args) {
|
||||
args = args;
|
||||
throw new Error("NOT_IMPLEMENTED");
|
||||
};
|
||||
if (!Array.isArray(args) || args.length !== 1) {
|
||||
throw new Error("INVALID_ARGS");
|
||||
}
|
||||
|
||||
commands.UPDATE_QUOTA = function (Env, args) {
|
||||
args = args;
|
||||
throw new Error("NOT_IMPLEMENTED");
|
||||
var unsafeKey = getCanonicalKey(args[0]);
|
||||
if (!unsafeKey) {
|
||||
throw new Error("INVALID_ARGS");
|
||||
}
|
||||
if (!Env.customLimits[unsafeKey]) {
|
||||
throw new Error("ENOENT");
|
||||
}
|
||||
|
||||
delete Env.customLimits[unsafeKey];
|
||||
delete Env.limits[unsafeKey];
|
||||
return true;
|
||||
};
|
||||
|
||||
// [<command>, <args>, <author>, <time>]
|
||||
|
@ -164,7 +181,6 @@ Decrees.createLineHandler = function (Env) {
|
|||
var Fs = require("fs");
|
||||
var Path = require("path");
|
||||
var readFileBin = require("./stream-file").readFileBin;
|
||||
var Util = require("./common-util");
|
||||
var Schedule = require("./schedule");
|
||||
var Fse = require("fs-extra");
|
||||
var nThen = require("nthen");
|
||||
|
|
Loading…
Reference in New Issue