diff --git a/lib/cartodb/controllers/map/anonymous.js b/lib/cartodb/controllers/map/anonymous.js index bf672a15..2ddd12c7 100644 --- a/lib/cartodb/controllers/map/anonymous.js +++ b/lib/cartodb/controllers/map/anonymous.js @@ -17,6 +17,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const lastModifiedHeader = require('../../middleware/last-modified-header'); const lastUpdatedTimeLayergroup = require('./middlewares/last-updated-time-layergroup'); const layerStats = require('./middlewares/layer-stats'); +const layergroupIdHeader = require('./middlewares/layergroup-id-header'); const sendResponse = require('../../middleware/send-response'); const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider'); const LayergroupMetadata = require('../../utils/layergroup-metadata'); @@ -103,7 +104,7 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () { lastModifiedHeader({ now: true }), lastUpdatedTimeLayergroup(), layerStats(this.pgConnection, this.statsBackend), - setLayergroupIdHeader(this.templateMaps ,useTemplateHash), + layergroupIdHeader(this.templateMaps ,useTemplateHash), setDataviewsAndWidgetsUrlsToLayergroupMetadata(this.layergroupMetadata), setAnalysesMetadataToLayergroup(this.layergroupMetadata, includeQuery), setTurboCartoMetadataToLayergroup(this.layergroupMetadata), @@ -218,22 +219,6 @@ function createLayergroup (mapBackend, userLimitsApi, pgConnection, affectedTabl }; } -function setLayergroupIdHeader (templateMaps, useTemplateHash) { - return function setLayergroupIdHeaderMiddleware (req, res, next) { - const { user, template } = res.locals; - const layergroup = res.body; - - if (useTemplateHash) { - var templateHash = templateMaps.fingerPrint(template).substring(0, 8); - layergroup.layergroupid = `${user}@${templateHash}@${layergroup.layergroupid}`; - } - - res.set('X-Layergroup-Id', layergroup.layergroupid); - - next(); - }; -} - function setDataviewsAndWidgetsUrlsToLayergroupMetadata (layergroupMetadata) { return function setDataviewsAndWidgetsUrlsToLayergroupMetadataMiddleware (req, res, next) { const { user, mapConfig } = res.locals; diff --git a/lib/cartodb/controllers/map/middlewares/layergroup-id-header.js b/lib/cartodb/controllers/map/middlewares/layergroup-id-header.js new file mode 100644 index 00000000..8141d6a6 --- /dev/null +++ b/lib/cartodb/controllers/map/middlewares/layergroup-id-header.js @@ -0,0 +1,15 @@ +module.exports = function setLayergroupIdHeader (templateMaps, useTemplateHash) { + return function setLayergroupIdHeaderMiddleware (req, res, next) { + const { user, template } = res.locals; + const layergroup = res.body; + + if (useTemplateHash) { + var templateHash = templateMaps.fingerPrint(template).substring(0, 8); + layergroup.layergroupid = `${user}@${templateHash}@${layergroup.layergroupid}`; + } + + res.set('X-Layergroup-Id', layergroup.layergroupid); + + next(); + }; +}; diff --git a/lib/cartodb/controllers/map/named.js b/lib/cartodb/controllers/map/named.js index cdff9367..e599212e 100644 --- a/lib/cartodb/controllers/map/named.js +++ b/lib/cartodb/controllers/map/named.js @@ -14,6 +14,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const lastModifiedHeader = require('../../middleware/last-modified-header'); const lastUpdatedTimeLayergroup = require('./middlewares/last-updated-time-layergroup'); const layerStats = require('./middlewares/layer-stats'); +const layergroupIdHeader = require('./middlewares/layergroup-id-header'); const sendResponse = require('../../middleware/send-response'); const NamedMapMapConfigProvider = require('../../models/mapconfig/provider/named-map-provider'); const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider'); @@ -114,7 +115,7 @@ NamedMapController.prototype.composeInstantiateTemplateMiddleware = function () lastModifiedHeader({ now: true }), lastUpdatedTimeLayergroup(), layerStats(this.pgConnection, this.statsBackend), - setLayergroupIdHeader(this.templateMaps ,useTemplateHash), + layergroupIdHeader(this.templateMaps ,useTemplateHash), setDataviewsAndWidgetsUrlsToLayergroupMetadata(this.layergroupMetadata), setAnalysesMetadataToLayergroup(this.layergroupMetadata, includeQuery), setTurboCartoMetadataToLayergroup(this.layergroupMetadata), @@ -225,22 +226,6 @@ function instantiateLayergroup (mapBackend, userLimitsApi, pgConnection, affecte }; } -function setLayergroupIdHeader (templateMaps, useTemplateHash) { - return function setLayergroupIdHeaderMiddleware (req, res, next) { - const { user, template } = res.locals; - const layergroup = res.body; - - if (useTemplateHash) { - var templateHash = templateMaps.fingerPrint(template).substring(0, 8); - layergroup.layergroupid = `${user}@${templateHash}@${layergroup.layergroupid}`; - } - - res.set('X-Layergroup-Id', layergroup.layergroupid); - - next(); - }; -} - function setDataviewsAndWidgetsUrlsToLayergroupMetadata (layergroupMetadata) { return function setDataviewsAndWidgetsUrlsToLayergroupMetadataMiddleware (req, res, next) { const { user, mapConfig } = res.locals;