From a9b0acc3177d56d9e3709da339712369435ab41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 21 Sep 2017 22:43:59 +0200 Subject: [PATCH] Use req2params middleware for static map (bbox & center) endpoint --- lib/cartodb/controllers/layergroup.js | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 963c8678..cae44899 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -71,15 +71,21 @@ LayergroupController.prototype.register = function(app) { '/:token/:layer/attributes/:fid', cors(), userMiddleware, this.attributes.bind(this)); - app.get(app.base_url_mapconfig + - '/static/center/:token/:z/:lat/:lng/:width/:height.:format', - cors(), userMiddleware, allowQueryParams(['layer']), - this.center.bind(this)); + app.get(app.base_url_mapconfig + '/static/center/:token/:z/:lat/:lng/:width/:height.:format', + cors(), + userMiddleware, + allowQueryParams(['layer']), + this.req2paramsMiddleware, + this.center.bind(this) + ); - app.get(app.base_url_mapconfig + - '/static/bbox/:token/:west,:south,:east,:north/:width/:height.:format', - cors(), userMiddleware, allowQueryParams(['layer']), - this.bbox.bind(this)); + app.get(app.base_url_mapconfig + '/static/bbox/:token/:west,:south,:east,:north/:width/:height.:format', + cors(), + userMiddleware, + allowQueryParams(['layer']), + this.req2paramsMiddleware, + this.bbox.bind(this) + ); // Undocumented/non-supported API endpoint methods. // Use at your own peril. @@ -339,17 +345,13 @@ LayergroupController.prototype.center = function(req, res, next) { LayergroupController.prototype.staticMap = function(req, res, width, height, zoom /* bounds */, center, next) { var format = req.params.format === 'jpg' ? 'jpeg' : 'png'; - req.params.layer = 'all'; - req.params.format = 'png'; + req.params.layer = req.params.layer || 'all'; + req.params.format = req.params.format || 'png'; var self = this; step( - function reqParams() { - self.req2params(req, res, this); - }, - function getImage(err) { - assert.ifError(err); + function getImage() { if (center) { self.previewBackend.getImage( new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, req.params),