Mercurial > hg > orthanc-stone
changeset 2269:d4a8203b3390
pass auth token in url for downloads and videos
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Mon, 26 Jan 2026 11:46:33 +0100 |
| parents | 1eae0a0ac6fd |
| children | a03b5f5461c6 |
| files | Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebApplication/app.js |
| diffstat | 2 files changed, 52 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS Fri Jan 02 13:22:24 2026 +0100 +++ b/Applications/StoneWebViewer/NEWS Mon Jan 26 11:46:33 2026 +0100 @@ -1,6 +1,14 @@ Pending changes in the mainline =============================== +Maintenance +----------- + +* Experimental: When an authorization token is passed in the url, downloads and videos are now re-using the token + as a url argument to allow native download by the browser instead of using blobs which might + be limited by the browser memory. + + Version 3.0 (2025-12-03) ========================
--- a/Applications/StoneWebViewer/WebApplication/app.js Fri Jan 02 13:22:24 2026 +0100 +++ b/Applications/StoneWebViewer/WebApplication/app.js Mon Jan 26 11:46:33 2026 +0100 @@ -53,10 +53,9 @@ var MOUSE_TOOL_CREATE_TEXT_ANNOTATION = 12; // New in 2.4 var MOUSE_TOOL_MAGNIFYING_GLASS = 13; // New in 2.4 -var hasAuthorizationToken = false; +var authorizationToken = null; var axiosHeaders = {}; - function getParameterFromUrl(key) { var url = window.location.search.substring(1); var args = url.split('&'); @@ -156,26 +155,38 @@ function TriggerDownloadFromUri(uri, filename, mime) { - if (hasAuthorizationToken) { - axios.get(uri, { - headers: axiosHeaders, - responseType: 'arraybuffer' - }) - .then(function(response) { - const blob = new Blob([ response.data ], { type: mime }); - const url = URL.createObjectURL(blob); + if (authorizationToken) { + if (false) // old code used up to v3.0 but sometimes limited by the memory available in the browser + { + axios.get(uri, { + headers: axiosHeaders, + responseType: 'arraybuffer' + }) + .then(function(response) { + const blob = new Blob([ response.data ], { type: mime }); + const url = URL.createObjectURL(blob); + + //window.open(url, '_blank'); - //window.open(url, '_blank'); - - // https://stackoverflow.com/a/19328891 + // https://stackoverflow.com/a/19328891 + var a = document.createElement("a"); + document.body.appendChild(a); + a.style = "display: none"; + a.href = url; + a.download = filename; + a.click(); + window.URL.revokeObjectURL(url); + }); + } + else + { var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; - a.href = url; + a.href = uri + (uri.includes('?') ? '&' : '?') + "token=" + authorizationToken; a.download = filename; a.click(); - window.URL.revokeObjectURL(url); - }); + } } else { // This version was used in Stone Web viewer <= 2.4, but doesn't @@ -341,15 +352,22 @@ else { var uri = that.globalConfiguration.OrthancApiRoot + '/instances/' + response.data[0] + '/frames/0/raw'; - if (hasAuthorizationToken) { - axios.get(uri, { - headers: axiosHeaders, - responseType: 'arraybuffer' - }) - .then(function(response) { - const blob = new Blob([ response.data ]); - that.videoUri = URL.createObjectURL(blob); - }); + if (authorizationToken) { + if (false) // old code used up to v3.0 but sometimes limited by the memory available in the browser + { + axios.get(uri, { + headers: axiosHeaders, + responseType: 'arraybuffer' + }) + .then(function(response) { + const blob = new Blob([ response.data ]); + that.videoUri = URL.createObjectURL(blob); + }); + } + else + { + that.videoUri = uri + (uri.includes('?') ? '&' : '?') + "token=" + authorizationToken; + } } else { that.videoUri = uri; } @@ -1595,7 +1613,7 @@ // Bearer token is new in Stone Web viewer 2.0 var token = getParameterFromUrl('token'); if (token !== undefined) { - hasAuthorizationToken = true; + authorizationToken = token; stone.AddHttpHeader('Authorization', 'Bearer ' + token); axiosHeaders['Authorization'] = 'Bearer ' + token; }
