diff --git a/lib/cartodb/backends/user-limits.js b/lib/cartodb/backends/user-limits.js index 3a137269..7ce0f2a3 100644 --- a/lib/cartodb/backends/user-limits.js +++ b/lib/cartodb/backends/user-limits.js @@ -41,21 +41,11 @@ UserLimitsBackend.prototype.getRenderLimits = function (username, apiKey, callba UserLimitsBackend.prototype.getTimeoutRenderLimit = function (username, apiKey, callback) { var self = this; - function isAuthorized() { - var next = this; - - if (!apiKey) { - return next(null, false); + isAuthorized(self.metadataBackend, username, apiKey, (err, authorized) => { + if (err) { + return callback(err); } - - self.metadataBackend.getUserMapKey(username, function (err, userApiKey) { - if (err) { - return next(err); - } - - return next(null, userApiKey === apiKey); - }); - }, + }) function getUserTimeoutRenderLimits(err, authorized) { var next = this; @@ -76,6 +66,20 @@ UserLimitsBackend.prototype.getTimeoutRenderLimit = function (username, apiKey, callback }; +function isAuthorized(metadataBackend, username, apiKey, callback) { + if (!apiKey) { + return callback(null, false); + } + + metadataBackend.getUserMapKey(username, function (err, userApiKey) { + if (err) { + return callback(err); + } + + return callback(null, userApiKey === apiKey); + }); +} + UserLimitsBackend.prototype.preprareRateLimit = function () { if (this.options.limits.rateLimitsEnabled) { this.metadataBackend.loadRateLimitsScript();