From eaff11ef6e143a5d9a738d8b1e171bedfe412985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Mon, 30 Jul 2018 17:15:04 +0200 Subject: [PATCH] remove step: function 1 --- lib/cartodb/backends/user-limits.js | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) 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();