|
|
|
@ -6,6 +6,9 @@ const Quota = module.exports;
|
|
|
|
|
const Keys = require("../keys");
|
|
|
|
|
const Package = require('../../package.json');
|
|
|
|
|
const Https = require("https");
|
|
|
|
|
const Util = require("../common-util");
|
|
|
|
|
|
|
|
|
|
var validLimitFields = ['limit', 'plan', 'note', 'users'];
|
|
|
|
|
|
|
|
|
|
Quota.isValidLimit = function (o) {
|
|
|
|
|
var valid = o && typeof(o) === 'object' &&
|
|
|
|
@ -13,7 +16,11 @@ Quota.isValidLimit = function (o) {
|
|
|
|
|
typeof(o.plan) === 'string' &&
|
|
|
|
|
typeof(o.note) === 'string' &&
|
|
|
|
|
// optionally contains a 'users' array
|
|
|
|
|
(Array.isArray(o.users) || typeof(o.users) === 'undefined');
|
|
|
|
|
(Array.isArray(o.users) || typeof(o.users) === 'undefined') &&
|
|
|
|
|
// check that the object contains only the expected fields
|
|
|
|
|
!Object.keys(o).some(function (k) {
|
|
|
|
|
return validLimitFields.indexOf(k) === -1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
|
};
|
|
|
|
@ -62,16 +69,8 @@ Env = {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|
Quota.queryAccountServer = function (Env, cb) {
|
|
|
|
|
cb = cb; // XXX
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Quota.updateCachedLimits = function (Env, cb) {
|
|
|
|
|
Quota.applyCustomLimits(Env);
|
|
|
|
|
if (Env.blockDailyCheck === true ||
|
|
|
|
|
(typeof(Env.blockDailyCheck) === 'undefined' && Env.adminEmail === false && Env.allowSubscriptions === false)) {
|
|
|
|
|
return void cb();
|
|
|
|
|
}
|
|
|
|
|
var queryAccountServer = function (Env, cb) {
|
|
|
|
|
var done = Util.once(Util.mkAsync(cb));
|
|
|
|
|
|
|
|
|
|
var body = JSON.stringify({
|
|
|
|
|
domain: Env.myDomain,
|
|
|
|
@ -104,31 +103,49 @@ Quota.updateCachedLimits = function (Env, cb) {
|
|
|
|
|
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);
|
|
|
|
|
//console.log('Env.limits', Env.limits);
|
|
|
|
|
cb(void 0);
|
|
|
|
|
done(void 0, json);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
cb(e);
|
|
|
|
|
done(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
req.on('error', function (e) {
|
|
|
|
|
Quota.applyCustomLimits(Env);
|
|
|
|
|
if (!Env.myDomain) { return cb(); }
|
|
|
|
|
if (!Env.myDomain) { return done(); }
|
|
|
|
|
// only return an error if your server allows subscriptions
|
|
|
|
|
cb(e);
|
|
|
|
|
done(e);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
req.end(body);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Quota.queryAccountServer = function (Env, cb) {
|
|
|
|
|
Env.batchAccountQuery('', cb, function (done) {
|
|
|
|
|
queryAccountServer(Env, done);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Quota.updateCachedLimits = function (Env, cb) {
|
|
|
|
|
Quota.applyCustomLimits(Env);
|
|
|
|
|
if (Env.blockDailyCheck === true ||
|
|
|
|
|
(typeof(Env.blockDailyCheck) === 'undefined' && Env.adminEmail === false && Env.allowSubscriptions === false)) {
|
|
|
|
|
return void cb();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quota.queryAccountServer(Env, function (err, json) {
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
if (!json) { return void cb(); }
|
|
|
|
|
|
|
|
|
|
Env.limits = json;
|
|
|
|
|
Quota.applyCustomLimits(Env);
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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.getUpdatedLimit = function (Env, safeKey, cb) {
|
|
|
|
|
Quota.updateCachedLimits(Env, function (err) {
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
|
|
|
|
|