@cornerstonejs/nifti-volume-loader 2.11.5 → 2.11.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,20 @@
1
1
  # @cornerstonejs/nifti-volume-loader
2
2
 
3
3
  Nifti volume loader for the cornerstone3D framework.
4
+
5
+ # Injecting headers
6
+
7
+ You can inject custom headers to the requests made by the loader. This is useful for authentication purposes.
8
+
9
+ ```js
10
+ import { init } from '@cornerstonejs/nifti-volume-loader';
11
+
12
+ niftiInit({
13
+ beforeSend: (xhr, headers, url) => {
14
+ headers['Cornerstone3D-Is-Awesome'] = 'True';
15
+ return headers;
16
+ },
17
+ });
18
+ ```
19
+
20
+ Now, every request made by the loader will have the `Cornerstone3D-Is-Awesome` header with the value `True`.
@@ -2,12 +2,23 @@ import { Enums, eventTarget, metaData, triggerEvent, utilities, } from '@corners
2
2
  import * as NiftiReader from 'nifti-reader-js';
3
3
  import { Events } from './enums';
4
4
  import { modalityScaleNifti } from './helpers';
5
+ import { getOptions } from './internal';
5
6
  const dataFetchStateMap = new Map();
6
7
  function fetchArrayBuffer({ url, signal, onload, }) {
7
8
  return new Promise((resolve, reject) => {
8
9
  const xhr = new XMLHttpRequest();
9
10
  xhr.open('GET', url, true);
11
+ const defaultHeaders = {};
12
+ const options = getOptions();
13
+ const beforeSendHeaders = options.beforeSend(xhr, defaultHeaders, url);
14
+ const headers = Object.assign({}, defaultHeaders, beforeSendHeaders);
10
15
  xhr.responseType = 'arraybuffer';
16
+ Object.keys(headers).forEach(function (key) {
17
+ if (headers[key] === null) {
18
+ return;
19
+ }
20
+ xhr.setRequestHeader(key, headers[key]);
21
+ });
11
22
  const onLoadHandler = function (e) {
12
23
  if (onload && typeof onload === 'function') {
13
24
  onload();
@@ -5,6 +5,7 @@ import Events from './enums/Events';
5
5
  import { NIFTI_LOADER_SCHEME } from './constants';
6
6
  import makeVolumeMetadata from './helpers/makeVolumeMetadata';
7
7
  import { getArrayConstructor } from './helpers/dataTypeCodeHelper';
8
+ import { getOptions } from './internal';
8
9
  export const urlsMap = new Map();
9
10
  const NIFTI1_HEADER_SIZE = 348;
10
11
  const NIFTI2_HEADER_SIZE = 540;
@@ -18,8 +19,17 @@ export async function fetchArrayBuffer({ url, onProgress, controller, onLoad, on
18
19
  let contentLength;
19
20
  const receivedLength = 0;
20
21
  const signal = controller.signal;
22
+ const options = getOptions();
23
+ const defaultHeaders = {};
24
+ const beforeSendHeaders = options.beforeSend?.(null, defaultHeaders, url);
25
+ const headers = Object.assign({}, defaultHeaders, beforeSendHeaders);
26
+ Object.keys(headers).forEach(function (key) {
27
+ if (headers[key] === null) {
28
+ headers[key] = undefined;
29
+ }
30
+ });
21
31
  try {
22
- const response = await fetch(url, { signal });
32
+ const response = await fetch(url, { signal, headers });
23
33
  if (!response.ok) {
24
34
  throw new Error(`HTTP error! status: ${response.status}`);
25
35
  }
@@ -2,4 +2,5 @@ import cornerstoneNiftiImageLoader from './cornerstoneNiftiImageLoader';
2
2
  import * as helpers from './helpers';
3
3
  import * as Enums from './enums';
4
4
  import { createNiftiImageIdsAndCacheMetadata } from './createNiftiImageIdsAndCacheMetadata';
5
- export { cornerstoneNiftiImageLoader, helpers, Enums, createNiftiImageIdsAndCacheMetadata, };
5
+ import init from './init';
6
+ export { cornerstoneNiftiImageLoader, helpers, Enums, createNiftiImageIdsAndCacheMetadata, init, };
package/dist/esm/index.js CHANGED
@@ -2,4 +2,5 @@ import cornerstoneNiftiImageLoader from './cornerstoneNiftiImageLoader';
2
2
  import * as helpers from './helpers';
3
3
  import * as Enums from './enums';
4
4
  import { createNiftiImageIdsAndCacheMetadata } from './createNiftiImageIdsAndCacheMetadata';
5
- export { cornerstoneNiftiImageLoader, helpers, Enums, createNiftiImageIdsAndCacheMetadata, };
5
+ import init from './init';
6
+ export { cornerstoneNiftiImageLoader, helpers, Enums, createNiftiImageIdsAndCacheMetadata, init, };
@@ -0,0 +1,3 @@
1
+ import type { LoaderOptions } from './types';
2
+ declare function init(options?: LoaderOptions): void;
3
+ export default init;
@@ -0,0 +1,5 @@
1
+ import { setOptions } from './internal';
2
+ function init(options = {}) {
3
+ setOptions(options);
4
+ }
5
+ export default init;
@@ -0,0 +1,2 @@
1
+ import { setOptions, getOptions } from './options';
2
+ export { setOptions, getOptions };
@@ -0,0 +1,2 @@
1
+ import { setOptions, getOptions } from './options';
2
+ export { setOptions, getOptions };
@@ -0,0 +1,3 @@
1
+ import type { LoaderOptions } from '../types';
2
+ export declare function setOptions(newOptions: LoaderOptions): void;
3
+ export declare function getOptions(): LoaderOptions;
@@ -0,0 +1,10 @@
1
+ let options = {
2
+ beforeSend() {
3
+ },
4
+ };
5
+ export function setOptions(newOptions) {
6
+ options = Object.assign(options, newOptions);
7
+ }
8
+ export function getOptions() {
9
+ return options;
10
+ }
@@ -0,0 +1,3 @@
1
+ export interface LoaderOptions {
2
+ beforeSend?: (xhr: XMLHttpRequest, defaultHeaders: Record<string, string>, url: string) => Record<string, string> | void;
3
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import type { LoaderOptions } from './LoaderOptions';
2
+ export type { LoaderOptions };
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/nifti-volume-loader",
3
- "version": "2.11.5",
3
+ "version": "2.11.7",
4
4
  "description": "Nifti Image Loader for Cornerstone3D",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -61,7 +61,7 @@
61
61
  "nifti-reader-js": "^0.6.8"
62
62
  },
63
63
  "peerDependencies": {
64
- "@cornerstonejs/core": "^2.11.5"
64
+ "@cornerstonejs/core": "^2.11.7"
65
65
  },
66
66
  "contributors": [
67
67
  {
@@ -74,5 +74,5 @@
74
74
  "type": "individual",
75
75
  "url": "https://ohif.org/donate"
76
76
  },
77
- "gitHead": "d99099549e677627a6081a6be471590def3958a2"
77
+ "gitHead": "a70a7d7c02057c5758bb8cb0957d757e4c445f80"
78
78
  }