Skip to content

Commit 7da073e

Browse files
authored
Add token to slide calls if present (#567)
1 parent 1d374cc commit 7da073e

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

apps/viewer/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function initCore() {
167167
if ($D.params.retry) {
168168
$UI.message.addError(e.message);
169169
// can't reach Slide and return to home page
170-
if (e.isServiceError) redirect($D.pages.table, e.message, 0);
170+
if (e.isServiceError) redirect($D.pages.table, e.message, 1);
171171
} else {
172172
// If this is our first attempt, try one more time.
173173
let params = new URLSearchParams(window.location.search);

common/PathdbMods.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function PathDbMods() {
1+
async function PathDbMods() {
22
console.log("PathDbMods()...");
33
// determine if user is authenicated
4-
fetch("/user/login_status?_format=json", {credentials: 'include'})
4+
await fetch("/user/login_status?_format=json", {credentials: 'include'})
55
.then(response => response.json())
66
.then(function(data) {
77
if (data!=0) {
@@ -11,6 +11,7 @@ function PathDbMods() {
1111
console.log(x)
1212
if (x.hasOwnProperty('token') && x.token) {
1313
document.cookie = "token=" + x.token + ";"
14+
console.log("set cookie, is now:" , document.cookie)
1415
}
1516
})
1617
} else {
@@ -49,9 +50,9 @@ function PathDbMods() {
4950
x.mpp = x.mpp_x
5051
}
5152
if (data.field_iip_path && data.field_iip_path.length >= 1) {
52-
x.location = data.field_iip_path[0].value;
53-
//x.location = "pathdb*" + pathdbid;
54-
x.url = "../../img/IIP/raw/?DeepZoom=" + x.location + ".dzi";
53+
//x.location = data.field_iip_path[0].value;
54+
x.location = "pathdb*" + pathdbid;
55+
x.url = "../../img/IIP/raw/?DeepZoom=pathdb*" + pathdbid + ".dzi";
5556
} else {
5657
throw "no iip path in pathdb data"
5758
}

common/dynamicLoadScript.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ const params = getUrlVars();
66
let file;
77
if (params.mode && params.mode==="pathdb"){
88
ImgloaderMode = 'iip';
9-
PathDbMods()
9+
PathDbMods().then(x=>{IsPackageLoading = true})
1010
}
1111
else if(params.slideId&&params.id&&params.slideId==="local"&&params.id.includes('http://localhost:8888')){
1212
ImgloaderMode = 'imgbox';
1313
NanoBorbMods()
1414
init_LocalStore()
15+
IsPackageLoading = true;
1516
}else{
1617
ImgloaderMode = 'iip';
18+
IsPackageLoading = true;
1719
// no mods to perform as of now
1820
}
19-
IsPackageLoading=true;

core/CaMic.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,20 @@ class CaMic {
168168
}
169169
const data = x[0];
170170
// check the slide on service side
171-
OpenSeadragon.makeAjaxRequest( {
172-
url: '../../img/IIP/raw/?DeepZoom='+ data['location'] + '.dzi',
173-
success: function( xhr ) {
171+
let checkSlideUrl = '../../img/IIP/raw/&DeepZoom='+ data['location'] + '.dzi';
172+
if (getCookie('token')) {
173+
checkSlideUrl = '../../img/IIP/raw/?token=' + getCookie('token') + '&DeepZoom='+ data['location'] + '.dzi';
174+
}
175+
fetch(checkSlideUrl, {credentials: 'include'}).then((z)=>{
176+
if (true) {
174177
this.openSlide(data, func);
175-
}.bind(this),
176-
error: function( xhr, exc ) {
177-
console.log(xhr, exc);
178-
Loading.text.textContent = 'Something Wrong With This Slide... X_X';
179-
if (func && typeof func === 'function') {
180-
func.call(null,
181-
{hasError: true,
182-
isServiceError: true,
183-
message: 'Something Wrong With This Slide... X_X'});
184-
}
185-
},
178+
} else {
179+
Loading.text.textContent = 'Slide Source Returned Status Code: ' + z.status;
180+
func.call(null,
181+
{hasError: true,
182+
isServiceError: true,
183+
message: 'Slide Source Returned Status Code: ' + z.status});
184+
}
186185
});
187186
})
188187
.catch((e)=>{
@@ -197,8 +196,12 @@ class CaMic {
197196
this.slideId = data['_id']['$oid'];
198197

199198
this.slideName = data['name'];
200-
201-
this.viewer.open('../../img/IIP/raw/?DeepZoom='+ data['location'] + '.dzi');
199+
// insert token if present
200+
let openSlideUrl = '../../img/IIP/raw/&DeepZoom='+ data['location'] + '.dzi';
201+
if (getCookie('token')) {
202+
openSlideUrl = '../../img/IIP/raw/?token=' + getCookie('token') + '&DeepZoom='+ data['location'] + '.dzi';
203+
}
204+
this.viewer.open(openSlideUrl);
202205
// set mpp
203206
this.mpp_x = +data['mpp-x'];
204207
this.mpp_y = +data['mpp-y'];

0 commit comments

Comments
 (0)