Skip to content

Commit

Permalink
NGPre tile source: factor path normalization
Browse files Browse the repository at this point in the history
Also do the normalization now on the final path, rather than the base.
This allows for additional modifications that are useful for Google
Cloud storage, where the only way to get back proper CORS headers seems
to be to use their object get API.
  • Loading branch information
tomka committed Jan 24, 2025
1 parent 039751e commit 1e8778d
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions django/applications/catmaid/static/js/tile-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,7 @@
'Your browser does not support features required for NeuroglancerPrecomputed mirrors');
}

this.datasetURL = this.baseURL.substring(0, this.baseURL.lastIndexOf('/'))
.replace(/^gs:\/\//, 'https://storage.googleapis.com/');
this.datasetURL = this.baseURL.substring(0, this.baseURL.lastIndexOf('/'));

let sliceDims = this.baseURL.substring(this.baseURL.lastIndexOf('/') + 1);
this.sliceDims = sliceDims.split('_').map(d => parseInt(d, 10));
Expand Down Expand Up @@ -1065,8 +1064,27 @@
});
}

normalizeUrl(path) {
// If this path points to Google Cloud storage, rebuild the path so that it uses the object
// get method (see https://cloud.google.com/storage/docs/json_api/v1/objects/get).
// Turn gs://h01-release/data/20210601/4nm_raw/
// into https://www.googleapis.com/storage/v1/b/h01-release/o/data%2F20210601%2F4nm_raw%2F
// Note that the new URL will also get a ?alt=media appended.
if (path.startsWith("gs://")) {
let components = path.split("/");
if (components.length < 4) {
throw new CATMAID.ValueError(`Unsupported Google Cloud URL: ${path}`);
}
let bucketName = components[2];
let subPath = components.slice(3).join("%2F");
return `https://www.googleapis.com/storage/v1/b/${bucketName}/o/${subPath}?alt=media`;
}

return path;
}

getCanaryUrl(project, stack) {
return `${this.rootURL}/info`;
return this.normalizeUrl(`${this.rootURL}/info`);
}

populateDatasetAttributes(zoomLevel = 0) {
Expand Down Expand Up @@ -1212,7 +1230,11 @@
() => {
let request = (options) => {
if (noCache) {
url += "?nocache=" + Date.now();
if (url.indexOf('?') >= 0) {
url += "&nocache=" + Date.now();
} else {
url += "?nocache=" + Date.now();
}
} else {
if (this.canaryCache.has(url)) {
return this.canaryCache.get(url);
Expand Down

0 comments on commit 1e8778d

Please sign in to comment.