2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-28 19:41:41 +08:00
|
|
|
module.exports = function setLayergroupIdHeader (templateMaps, useTemplateHash) {
|
|
|
|
return function setLayergroupIdHeaderMiddleware (req, res, next) {
|
|
|
|
const { user, template } = res.locals;
|
|
|
|
const layergroup = res.body;
|
|
|
|
|
|
|
|
if (useTemplateHash) {
|
2020-04-29 23:26:33 +08:00
|
|
|
const templateHash = templateMaps.fingerPrint(template).substring(0, 8);
|
2018-03-28 19:41:41 +08:00
|
|
|
layergroup.layergroupid = `${user}@${templateHash}@${layergroup.layergroupid}`;
|
2020-04-29 23:26:33 +08:00
|
|
|
res.locals.templateHash = templateHash;
|
2018-03-28 19:41:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
res.set('X-Layergroup-Id', layergroup.layergroupid);
|
|
|
|
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|