changeset 79:abcaf34cfd98 default tip

added support for token url argument
author Alain Mazy <am@orthanc.team>
date Tue, 23 Sep 2025 12:12:00 +0200
parents 7baff50b102b
children
files .hgignore NEWS WebApplications/o3dv.js WebApplications/three.js
diffstat 4 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Jan 17 14:21:31 2025 +0100
+++ b/.hgignore	Tue Sep 23 12:12:00 2025 +0200
@@ -11,3 +11,4 @@
 i/
 s/
 *.orig
+.vscode/
\ No newline at end of file
--- a/NEWS	Fri Jan 17 14:21:31 2025 +0100
+++ b/NEWS	Tue Sep 23 12:12:00 2025 +0200
@@ -3,6 +3,9 @@
 
 * Added configuration option "STL.3DHOP.CanvasStyle" to change the
   background of the 3DHOP viewer
+* Basic Viewer + Online3DViewer: Added support for a 'token' get url 
+  argument that is then passed as an 'Authorization' HTTP header when 
+  querying the model from the Orthanc Rest API.
 
 
 Version 1.2 (2024-06-16)
--- a/WebApplications/o3dv.js	Fri Jan 17 14:21:31 2025 +0100
+++ b/WebApplications/o3dv.js	Tue Sep 23 12:12:00 2025 +0200
@@ -40,7 +40,26 @@
 };
 
 var instanceId = GetUrlParameter('instance');
+var token = GetUrlParameter('token');
 
+async function loadStl(viewer, instanceId) {
+  
+  var headers = {};
+  if (token) {
+      headers['Authorization'] = 'Bearer ' + token
+  }
+
+  const response = await fetch('../../instances/' + instanceId + '/stl', {
+    headers: headers
+  });
+
+  const blob = await response.blob();
+  const file = new File([blob], 'model.stl');
+
+  viewer.LoadModelFromInputFiles([
+    new OV.InputFile('model.stl', OV.FileSource.File, file),
+  ]);
+}
 
 window.addEventListener ('load', () => {
   let parentDiv = document.getElementById ('viewer');
@@ -55,7 +74,5 @@
     edgeSettings : new OV.EdgeSettings (false, new OV.RGBColor (255, 255, 255), 1)
   });
 
-  viewer.LoadModelFromInputFiles ([
-    new OV.InputFile('model.stl', OV.FileSource.Url, '../../instances/' + instanceId + '/stl'),
-  ]);
+  loadStl(viewer, instanceId);
 });
--- a/WebApplications/three.js	Fri Jan 17 14:21:31 2025 +0100
+++ b/WebApplications/three.js	Tue Sep 23 12:12:00 2025 +0200
@@ -64,6 +64,12 @@
 scene.add(light2);
 
 const loader = new STLLoader()
+
+var token = GetUrlParameter('token');
+if (token) {
+  loader.setRequestHeader({'Authorization': 'Bearer ' + token})
+}
+
 loader.load(
   //'../../instances/' + instanceId + '/content/0042-0011',
   '../../instances/' + instanceId + '/stl',