Skip to content

Commit

Permalink
feat: Add beforeProcessing hook to WADO-URI XMLHttpRequest (#338)
Browse files Browse the repository at this point in the history
* add before processing hook to wadouri xhr

* Update comments

* Eslint

* Linting issues

* Lint update

* Ditch second argument of resolve

* Run lint
  • Loading branch information
igoroctaviano committed Dec 8, 2020
1 parent c504bb1 commit 43dbacb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/dicomImageLoader/config/webpack/webpack-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const devConfig = {
]
};

module.exports = merge(baseConfig, devConfig);
module.exports = merge(baseConfig, devConfig);
4 changes: 4 additions & 0 deletions packages/dicomImageLoader/src/imageLoader/internal/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let options = {
// callback allowing customization of the xhr (e.g. adding custom auth headers, cors, etc)
beforeSend(/* xhr, imageId */) {},
// callback allowing modification of the xhr response before creating image objects
beforeProcessing(xhr) {
return Promise.resolve(xhr.response);
},
// callback allowing modification of newly created image objects
imageCreated(/* image */) {},
strict: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ function xhrRequest(url, imageId, headers = {}, params = {}) {
// TODO: consider sending out progress messages here as we receive the pixel data
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(xhr.response, xhr);
options
.beforeProcessing(xhr)
.then(resolve)
.catch(() => {
errorInterceptor(xhr);
// request failed, reject the Promise
reject(xhr);
});
} else {
errorInterceptor(xhr);
// request failed, reject the Promise
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import metaDataManager from './metaDataManager.js';
import getPixelData from './getPixelData.js';
import createImage from '../createImage.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function initialize(configObject) {
config = configObject;

config.maxWebWorkers =
config.maxWebWorkers || (navigator.hardwareConcurrency || 1);
config.maxWebWorkers || navigator.hardwareConcurrency || 1;

// Spawn new web workers
if (!config.startWebWorkersOnDemand) {
Expand Down

0 comments on commit 43dbacb

Please sign in to comment.