|
|
|
@ -35,25 +35,12 @@ Quota.applyCustomLimits = function (Env) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
Quota.updateCachedLimits = function (Env, cb) {
|
|
|
|
|
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(Env.defaultStorageLimit) === 'number'?
|
|
|
|
|
Env.defaultStorageLimit: Core.DEFAULT_LIMIT;
|
|
|
|
|
|
|
|
|
|
var userId;
|
|
|
|
|
if (publicKey) {
|
|
|
|
|
userId = Util.unescapeKeyCharacters(publicKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body = JSON.stringify({
|
|
|
|
|
domain: Env.myDomain,
|
|
|
|
@ -86,14 +73,7 @@ Quota.updateLimits = function (Env, publicKey, cb) { // FIXME BATCH?S
|
|
|
|
|
var json = JSON.parse(str);
|
|
|
|
|
Env.limits = json;
|
|
|
|
|
Quota.applyCustomLimits(Env);
|
|
|
|
|
|
|
|
|
|
var l;
|
|
|
|
|
if (userId) {
|
|
|
|
|
var limit = Env.limits[userId];
|
|
|
|
|
l = limit && typeof limit.limit === "number" ?
|
|
|
|
|
[limit.limit, limit.plan, limit.note] : [defaultLimit, '', ''];
|
|
|
|
|
}
|
|
|
|
|
cb(void 0, l);
|
|
|
|
|
cb(void 0);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
cb(e);
|
|
|
|
|
}
|
|
|
|
@ -109,4 +89,19 @@ Quota.updateLimits = function (Env, publicKey, cb) { // FIXME BATCH?S
|
|
|
|
|
req.end(body);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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.getUpdatedLimit = function (Env, safeKey, cb) { // FIXME BATCH?S
|
|
|
|
|
Quota.updateCachedLimits(Env, function (err) {
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
|
|
|
|
|
var limit = Env.limits[safeKey];
|
|
|
|
|
|
|
|
|
|
if (limit && typeof(limit.limit) === 'number') {
|
|
|
|
|
return void cb(void 0, [limit.limit, limit.plan, limit.note]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return void cb(void 0, [Env.defaultStorageLimit, '', '']);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|