WIP massive rpc refactor
This commit is contained in:
@@ -7,7 +7,7 @@ const Util = require("../common-util");
|
||||
const Package = require('../../package.json');
|
||||
const Https = require("https");
|
||||
|
||||
Quota.applyCustomLimits = function (Env, config) {
|
||||
Quota.applyCustomLimits = function (Env) {
|
||||
var isLimit = function (o) {
|
||||
var valid = o && typeof(o) === 'object' &&
|
||||
typeof(o.limit) === 'number' &&
|
||||
@@ -16,7 +16,7 @@ Quota.applyCustomLimits = function (Env, config) {
|
||||
return valid;
|
||||
};
|
||||
|
||||
// read custom limits from the config
|
||||
// read custom limits from the Environment (taken from config)
|
||||
var customLimits = (function (custom) {
|
||||
var limits = {};
|
||||
Object.keys(custom).forEach(function (k) {
|
||||
@@ -27,7 +27,7 @@ Quota.applyCustomLimits = function (Env, config) {
|
||||
});
|
||||
});
|
||||
return limits;
|
||||
}(config.customLimits || {}));
|
||||
}(Env.customLimits || {}));
|
||||
|
||||
Object.keys(customLimits).forEach(function (k) {
|
||||
if (!isLimit(customLimits[k])) { return; }
|
||||
@@ -37,17 +37,18 @@ Quota.applyCustomLimits = function (Env, config) {
|
||||
|
||||
// The limits object contains storage limits for all the publicKey that have paid
|
||||
// To each key is associated an object containing the 'limit' value and a 'note' explaining that limit
|
||||
Quota.updateLimits = function (Env, config, publicKey, cb) { // FIXME BATCH?S
|
||||
// XXX maybe the use case with a publicKey should be a different command that calls this?
|
||||
Quota.updateLimits = function (Env, publicKey, cb) { // FIXME BATCH?S
|
||||
|
||||
if (config.adminEmail === false) {
|
||||
Quota.applyCustomLimits(Env, config);
|
||||
if (config.allowSubscriptions === false) { return; }
|
||||
if (Env.adminEmail === false) {
|
||||
Quota.applyCustomLimits(Env);
|
||||
if (Env.allowSubscriptions === false) { return; }
|
||||
throw new Error("allowSubscriptions must be false if adminEmail is false");
|
||||
}
|
||||
if (typeof cb !== "function") { cb = function () {}; }
|
||||
|
||||
var defaultLimit = typeof(config.defaultStorageLimit) === 'number'?
|
||||
config.defaultStorageLimit: Core.DEFAULT_LIMIT;
|
||||
var defaultLimit = typeof(Env.defaultStorageLimit) === 'number'?
|
||||
Env.defaultStorageLimit: Core.DEFAULT_LIMIT;
|
||||
|
||||
var userId;
|
||||
if (publicKey) {
|
||||
@@ -55,9 +56,9 @@ Quota.updateLimits = function (Env, config, publicKey, cb) { // FIXME BATCH?S
|
||||
}
|
||||
|
||||
var body = JSON.stringify({
|
||||
domain: config.myDomain,
|
||||
subdomain: config.mySubdomain || null,
|
||||
adminEmail: config.adminEmail,
|
||||
domain: Env.myDomain,
|
||||
subdomain: Env.mySubdomain || null,
|
||||
adminEmail: Env.adminEmail,
|
||||
version: Package.version
|
||||
});
|
||||
var options = {
|
||||
@@ -84,7 +85,7 @@ Quota.updateLimits = function (Env, config, publicKey, cb) { // FIXME BATCH?S
|
||||
try {
|
||||
var json = JSON.parse(str);
|
||||
Env.limits = json;
|
||||
Quota.applyCustomLimits(Env, config);
|
||||
Quota.applyCustomLimits(Env);
|
||||
|
||||
var l;
|
||||
if (userId) {
|
||||
@@ -100,8 +101,8 @@ Quota.updateLimits = function (Env, config, publicKey, cb) { // FIXME BATCH?S
|
||||
});
|
||||
|
||||
req.on('error', function (e) {
|
||||
Quota.applyCustomLimits(Env, config);
|
||||
if (!config.domain) { return cb(); }
|
||||
Quota.applyCustomLimits(Env);
|
||||
if (!Env.domain) { return cb(); } // XXX
|
||||
cb(e);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user