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) {
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));
if (cdnUrls) {
@ -73,18 +73,20 @@ ResourceLocator.prototype.getUrls = function(username, resourcePath) {
}
};
function urlForTemplate(tpl, username, cdnDomain, resource) {
if (cdnDomain.hasOwnProperty('urlTemplate')) {
function urlForTemplate(tpl, username, cdnDomain, resource, templated) {
cdnDomain = cdnDomain || {};
if (templated) {
return {
urlTemplate: tpl({
cdn_url: cdnDomain.urlTemplate,
cdn_url: (cdnDomain.hasOwnProperty('urlTemplate') ? cdnDomain.urlTemplate : cdnDomain),
user: username,
port: this.environment.port,
resource: resource.getPath()
}),
subdomains: cdnDomain.subdomains
subdomains: cdnDomain.subdomains || []
};
} else if (Array.isArray(cdnDomain)) {
}
if (Array.isArray(cdnDomain)) {
return cdnDomain.map(d => tpl({
cdn_url: d,
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 cdnDomain = getCdnDomain(this.environment.serverMetadata, resource) || {};
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) {
urls.https = urlForTemplate(this.resourcesUrlTemplates.https, username, cdnDomain.https, resource);
urls.https = urlForTemplate(this.resourcesUrlTemplates.https, username, cdnDomain.https, resource, templated);
}
return urls;