Windshaft-cartodb/lib/models/layergroup-token.js

34 lines
745 B
JavaScript
Raw Normal View History

'use strict';
2015-07-08 05:46:58 +08:00
/**
* @param {String} token might match the following pattern: {user}@{tpl_id}@{token}:{cache_buster}
*/
2019-10-22 01:07:24 +08:00
function parse (token) {
2020-04-29 22:44:14 +08:00
var signer, cacheBuster, templateHash;
2015-07-08 05:46:58 +08:00
var tokenSplit = token.split(':');
token = tokenSplit[0];
if (tokenSplit.length > 1) {
cacheBuster = tokenSplit[1];
}
tokenSplit = token.split('@');
2019-10-22 01:07:24 +08:00
if (tokenSplit.length > 1) {
2015-07-08 05:46:58 +08:00
signer = tokenSplit.shift();
2019-10-22 01:07:24 +08:00
if (tokenSplit.length > 1) {
2020-04-29 22:44:14 +08:00
templateHash = tokenSplit.shift();
2015-07-08 05:46:58 +08:00
}
token = tokenSplit.shift();
}
return {
token: token,
signer: signer,
2020-04-29 22:44:14 +08:00
cacheBuster: cacheBuster,
templateHash: templateHash
2015-07-08 05:46:58 +08:00
};
}
2020-04-29 22:44:14 +08:00
2015-07-08 05:46:58 +08:00
module.exports.parse = parse;