Be explicit about requesting urlTemplate+subdomains format

This commit is contained in:
Raul Ochoa 2018-01-03 23:33:59 +00:00
parent 2cda43dc8d
commit d5b5ef584d

View File

@ -42,7 +42,7 @@ ResourceLocator.prototype.getTileUrls = function(username, resourcePath) {
ResourceLocator.prototype.getTemplateUrls = function(username, resourcePath) { ResourceLocator.prototype.getTemplateUrls = function(username, resourcePath) {
if (this.resourcesUrlTemplates) { if (this.resourcesUrlTemplates) {
return this.getUrlsFromTemplate(username, new TemplateResource(resourcePath)); return this.getUrlsFromTemplate(username, new TemplateResource(resourcePath), true);
} }
var cdnUrls = getCdnUrls(this.environment.serverMetadata, username, new TemplateResource(resourcePath)); var cdnUrls = getCdnUrls(this.environment.serverMetadata, username, new TemplateResource(resourcePath));
if (cdnUrls) { if (cdnUrls) {
@ -73,18 +73,20 @@ ResourceLocator.prototype.getUrls = function(username, resourcePath) {
} }
}; };
function urlForTemplate(tpl, username, cdnDomain, resource) { function urlForTemplate(tpl, username, cdnDomain, resource, templated) {
if (cdnDomain.hasOwnProperty('urlTemplate')) { cdnDomain = cdnDomain || {};
if (templated) {
return { return {
urlTemplate: tpl({ urlTemplate: tpl({
cdn_url: cdnDomain.urlTemplate, cdn_url: (cdnDomain.hasOwnProperty('urlTemplate') ? cdnDomain.urlTemplate : cdnDomain),
user: username, user: username,
port: this.environment.port, port: this.environment.port,
resource: resource.getPath() resource: resource.getPath()
}), }),
subdomains: cdnDomain.subdomains subdomains: cdnDomain.subdomains || []
}; };
} else if (Array.isArray(cdnDomain)) { }
if (Array.isArray(cdnDomain)) {
return cdnDomain.map(d => tpl({ return cdnDomain.map(d => tpl({
cdn_url: d, cdn_url: d,
user: username, user: username,
@ -101,15 +103,14 @@ function urlForTemplate(tpl, username, cdnDomain, resource) {
} }
} }
ResourceLocator.prototype.getUrlsFromTemplate = function(username, resource) { ResourceLocator.prototype.getUrlsFromTemplate = function(username, resource, templated) {
var urls = {}; var urls = {};
var cdnDomain = getCdnDomain(this.environment.serverMetadata, resource) || {}; var cdnDomain = getCdnDomain(this.environment.serverMetadata, resource) || {};
if (this.resourcesUrlTemplates.http) { if (this.resourcesUrlTemplates.http) {
urls.http = urlForTemplate(this.resourcesUrlTemplates.http, username, cdnDomain.http, resource); urls.http = urlForTemplate(this.resourcesUrlTemplates.http, username, cdnDomain.http, resource, templated);
} }
if (this.resourcesUrlTemplates.https) { if (this.resourcesUrlTemplates.https) {
urls.https = urlForTemplate(this.resourcesUrlTemplates.https, username, cdnDomain.https, resource); urls.https = urlForTemplate(this.resourcesUrlTemplates.https, username, cdnDomain.https, resource, templated);
} }
return urls; return urls;