All files / extensions/default/src/utils getDirectURL.ts

4.54% Statements 1/22
0% Branches 0/15
0% Functions 0/2
4.54% Lines 1/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                      34x                                                                                            
import { utils } from '@ohif/core';
 
import getBulkdataValue from './getBulkdataValue';
import createRenderedRetrieve from './createRenderedRetrieve';
 
/**
 * Generates a URL that can be used for direct retrieve of the bulkdata
 *
 * @param {object} params
 * @param {string} params.tag is the tag name of the URL to retrieve
 * @param {string} params.defaultPath path for the pixel data url
 * @param {object} params.instance is the instance object that the tag is in
 * @param {string} params.defaultType is the mime type of the response
 * @param {string} params.singlepart is the type of the part to retrieve
 * @param {string} params.fetchPart unknown?
 * @param {string} params.url unknown?
 * @returns an absolute URL to the resource, if the absolute URL can be retrieved as singlepart,
 *    or is already retrieved, or a promise to a URL for such use if a BulkDataURI
 */
const getDirectURL = (config, params) => {
  const { singlepart } = config;
  const {
    instance,
    tag = 'PixelData',
    defaultType = 'video/mp4',
    singlepart: fetchPart = 'video',
    url = null,
  } = params;
 
  Iif (url) {
    return url;
  }
 
  const value = instance[tag];
  Iif (value) {
    Iif (value.DirectRetrieveURL) {
      return value.DirectRetrieveURL;
    }
 
    Iif (value.InlineBinary) {
      const blob = utils.b64toBlob(value.InlineBinary, defaultType);
      value.DirectRetrieveURL = URL.createObjectURL(blob);
      return value.DirectRetrieveURL;
    }
 
    Iif (!singlepart || (singlepart !== true && singlepart.indexOf(fetchPart) === -1)) {
      Iif (value.retrieveBulkData) {
        // Try the specified retrieve type.
        const options = {
          mediaType: defaultType,
        };
        return value.retrieveBulkData(options).then(arr => {
          value.DirectRetrieveURL = URL.createObjectURL(new Blob([arr], { type: defaultType }));
          return value.DirectRetrieveURL;
        });
      }
      console.warn('Unable to retrieve', tag, 'from', instance);
      return undefined;
    }
  }
 
  return createRenderedRetrieve(config, params) || getBulkdataValue(config, params);
};
 
export default getDirectURL;