Skip to content

Commit

Permalink
Add url load forceLoader option, fixes #1629
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Mar 15, 2024
1 parent 9611654 commit 928a5b2
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 63 deletions.
31 changes: 20 additions & 11 deletions src/io/dicomDataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export class DicomDataLoader {
/**
* Check if the loader can load the provided url.
* True if:
* - the options.forceLoader is 'dicom'
* - the options.requestHeaders contains a 'Accept: application/dicom'
* - the url has a 'contentType' and it is 'application/dicom'
* (as in wado urls)
* - the url has no 'contentType' and no extension or the extension is 'dcm'
Expand All @@ -118,17 +120,24 @@ export class DicomDataLoader {
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/dicom' and no '+'
return startsWith(acceptHeader.value, 'application/dicom') &&
acceptHeader.value[18] !== '+';
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'dicom') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/dicom' and no '+'
return startsWith(acceptHeader.value, 'application/dicom') &&
acceptHeader.value[18] !== '+';
}
}
}

Expand Down
29 changes: 18 additions & 11 deletions src/io/jsonTextLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,24 @@ export class JSONTextLoader {
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/json' or 'application/dicom+json
return startsWith(acceptHeader.value, 'application/json') ||
startsWith(acceptHeader.value, 'application/dicom+json');
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'json') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/json' or 'application/dicom+json
return startsWith(acceptHeader.value, 'application/json') ||
startsWith(acceptHeader.value, 'application/dicom+json');
}
}
}

Expand Down
29 changes: 18 additions & 11 deletions src/io/multipartLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,27 @@ export class MultipartLoader {
* Check if the loader can load the provided url.
*
* @param {string} url The url to check.
* @param {object} [options] The url request options.
* @param {object} [options] Optional url request options.
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'multipart/related'
return startsWith(acceptHeader.value, 'multipart/related');
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'multipart') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'multipart/related'
return startsWith(acceptHeader.value, 'multipart/related');
}
}
}

Expand Down
27 changes: 17 additions & 10 deletions src/io/rawImageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,23 @@ export class RawImageLoader {
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'image/'
return startsWith(acceptHeader.value, 'image/');
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'rawimage') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'image/'
return startsWith(acceptHeader.value, 'image/');
}
}
}

Expand Down
27 changes: 17 additions & 10 deletions src/io/rawVideoLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,23 @@ export class RawVideoLoader {
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'video/'
return startsWith(acceptHeader.value, 'video/');
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'rawvideo') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'video/'
return startsWith(acceptHeader.value, 'video/');
}
}
}

Expand Down
27 changes: 17 additions & 10 deletions src/io/zipLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,23 @@ export class ZipLoader {
* @returns {boolean} True if the url can be loaded.
*/
canLoadUrl(url, options) {
// check options.requestHeaders for 'Accept'
if (typeof options !== 'undefined' &&
typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/zip'
return startsWith(acceptHeader.value, 'application/zip');
// check options
if (typeof options !== 'undefined') {
// check options.forceLoader
if (typeof options.forceLoader !== 'undefined' &&
options.forceLoader === 'zip') {
return true;
}
// check options.requestHeaders for 'Accept'
if (typeof options.requestHeaders !== 'undefined') {
const isNameAccept = function (element) {
return element.name === 'Accept';
};
const acceptHeader = options.requestHeaders.find(isNameAccept);
if (typeof acceptHeader !== 'undefined') {
// starts with 'application/zip'
return startsWith(acceptHeader.value, 'application/zip');
}
}
}

Expand Down

0 comments on commit 928a5b2

Please sign in to comment.