From 2c9d30e04279f59b0cdb7da03301743f0c6f23db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 10 May 2017 17:49:28 +0200 Subject: [PATCH] Be more flexible validating buffer-size customization --- .../adapter/mapconfig-named-map-adapter.js | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/cartodb/models/mapconfig/adapter/mapconfig-named-map-adapter.js b/lib/cartodb/models/mapconfig/adapter/mapconfig-named-map-adapter.js index 76e8f3f5..3010db4a 100644 --- a/lib/cartodb/models/mapconfig/adapter/mapconfig-named-map-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/mapconfig-named-map-adapter.js @@ -1,35 +1,22 @@ -var _ = require('underscore'); - function MapConfigNamedMapAdapter() { } module.exports = MapConfigNamedMapAdapter; +var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson']; + MapConfigNamedMapAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) { - if (context.templateParams && - context.templateParams.buffersize && - isValidBufferSize(context.templateParams.buffersize)) { - requestMapConfig.buffersize = context.templateParams.buffersize; + if (!context.templateParams || !context.templateParams.buffersize) { + return callback(null, requestMapConfig); } + formats.forEach(function (format) { + if (Number.isFinite(context.templateParams.buffersize[format])) { + requestMapConfig.buffersize[format] = context.templateParams.buffersize[format]; + } + }); + process.nextTick(function () { callback(null, requestMapConfig); }); }; - -function isValidBufferSize (bufferSize) { - var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson']; - - if (!_.isObject(bufferSize) || (_.isArray(bufferSize) || _.isFunction(bufferSize))) { - return false; - } - - for (var index = 0; index < formats.length; index++) { - var bufferSizeByFormat = bufferSize[formats[index]]; - if (bufferSizeByFormat && !Number.isFinite(bufferSizeByFormat)) { - return false; - } - } - - return true; -}