simpler limit updates
This commit is contained in:
parent
bde17a62a1
commit
f17d14fd99
@ -35,25 +35,12 @@ Quota.applyCustomLimits = function (Env) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// The limits object contains storage limits for all the publicKey that have paid
|
Quota.updateCachedLimits = function (Env, cb) {
|
||||||
// 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
|
|
||||||
|
|
||||||
if (Env.adminEmail === false) {
|
if (Env.adminEmail === false) {
|
||||||
Quota.applyCustomLimits(Env);
|
Quota.applyCustomLimits(Env);
|
||||||
if (Env.allowSubscriptions === false) { return; }
|
if (Env.allowSubscriptions === false) { return; }
|
||||||
throw new Error("allowSubscriptions must be false if adminEmail is false");
|
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({
|
var body = JSON.stringify({
|
||||||
domain: Env.myDomain,
|
domain: Env.myDomain,
|
||||||
@ -86,14 +73,7 @@ Quota.updateLimits = function (Env, publicKey, cb) { // FIXME BATCH?S
|
|||||||
var json = JSON.parse(str);
|
var json = JSON.parse(str);
|
||||||
Env.limits = json;
|
Env.limits = json;
|
||||||
Quota.applyCustomLimits(Env);
|
Quota.applyCustomLimits(Env);
|
||||||
|
cb(void 0);
|
||||||
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);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cb(e);
|
cb(e);
|
||||||
}
|
}
|
||||||
@ -109,4 +89,19 @@ Quota.updateLimits = function (Env, publicKey, cb) { // FIXME BATCH?S
|
|||||||
req.end(body);
|
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, '', '']);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ const AUTHENTICATED_USER_TARGETED = {
|
|||||||
const AUTHENTICATED_USER_SCOPED = {
|
const AUTHENTICATED_USER_SCOPED = {
|
||||||
GET_HASH: Pinning.getHash,
|
GET_HASH: Pinning.getHash,
|
||||||
GET_TOTAL_SIZE: Pinning.getTotalSize,
|
GET_TOTAL_SIZE: Pinning.getTotalSize,
|
||||||
UPDATE_LIMITS: Quota.updateLimits,
|
UPDATE_LIMITS: Quota.getUpdatedLimit,
|
||||||
GET_LIMIT: Pinning.getLimit,
|
GET_LIMIT: Pinning.getLimit,
|
||||||
EXPIRE_SESSION: Core.expireSessionAsync,
|
EXPIRE_SESSION: Core.expireSessionAsync,
|
||||||
REMOVE_PINS: Pinning.removePins,
|
REMOVE_PINS: Pinning.removePins,
|
||||||
@ -214,7 +214,6 @@ RPC.create = function (config, cb) {
|
|||||||
var Env = {
|
var Env = {
|
||||||
historyKeeper: config.historyKeeper,
|
historyKeeper: config.historyKeeper,
|
||||||
intervals: config.intervals || {},
|
intervals: config.intervals || {},
|
||||||
defaultStorageLimit: config.defaultStorageLimit,
|
|
||||||
maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024),
|
maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024),
|
||||||
Sessions: {},
|
Sessions: {},
|
||||||
paths: {},
|
paths: {},
|
||||||
@ -235,6 +234,10 @@ RPC.create = function (config, cb) {
|
|||||||
domain: config.domain // XXX
|
domain: config.domain // XXX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Env.defaultStorageLimit = typeof(config.defaultStorageLimit) === 'number' && config.defaultStorageLimit > 0?
|
||||||
|
config.defaultStorageLimit:
|
||||||
|
Core.DEFAULT_LIMIT;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Env.admins = (config.adminKeys || []).map(function (k) {
|
Env.admins = (config.adminKeys || []).map(function (k) {
|
||||||
k = k.replace(/\/+$/, '');
|
k = k.replace(/\/+$/, '');
|
||||||
@ -254,7 +257,7 @@ RPC.create = function (config, cb) {
|
|||||||
paths.blob = keyOrDefaultString('blobPath', './blob');
|
paths.blob = keyOrDefaultString('blobPath', './blob');
|
||||||
|
|
||||||
var updateLimitDaily = function () {
|
var updateLimitDaily = function () {
|
||||||
Quota.updateLimits(Env, undefined, function (e) {
|
Quota.updateCachedLimits(Env, function (e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
WARN('limitUpdate', e);
|
WARN('limitUpdate', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user