Skip to content

Commit c292726

Browse files
Christian-e-SChristian El Salloum
andauthored
feat(progress) progressCallback for requests
If provided, progressCallback in the options is now handed over to the XMLHttp requests for all major functions, that handle large data (#44) Co-authored-by: Christian El Salloum <[email protected]>
1 parent 6312dd7 commit c292726

File tree

2 files changed

+75
-24
lines changed

2 files changed

+75
-24
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.js

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,18 +1191,23 @@ class DICOMwebClient {
11911191
}
11921192
}
11931193

1194+
let progressCallback = false;
1195+
if ("progressCallback" in options) {
1196+
progressCallback = options.progressCallback;
1197+
}
1198+
11941199
if (!mediaTypes) {
1195-
return this._httpGetMultipartApplicationOctetStream(url, false, false, false, false, withCredentials);
1200+
return this._httpGetMultipartApplicationOctetStream(url, false, false, false, progressCallback, withCredentials);
11961201
}
11971202

11981203
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
11991204

12001205
if (commonMediaType === MEDIATYPES.OCTET_STREAM) {
1201-
return this._httpGetMultipartApplicationOctetStream(url, mediaTypes, false, false, false, withCredentials);
1206+
return this._httpGetMultipartApplicationOctetStream(url, mediaTypes, false, false, progressCallback, withCredentials);
12021207
} else if (commonMediaType.startsWith("image")) {
1203-
return this._httpGetMultipartImage(url, mediaTypes, false, false, false, false, withCredentials);
1208+
return this._httpGetMultipartImage(url, mediaTypes, false, false, false, progressCallback, withCredentials);
12041209
} else if (commonMediaType.startsWith("video")) {
1205-
return this._httpGetMultipartVideo(url, mediaTypes, false, false, false, false, withCredentials);
1210+
return this._httpGetMultipartVideo(url, mediaTypes, false, false, false, progressCallback, withCredentials);
12061211
}
12071212

12081213
throw new Error(
@@ -1250,23 +1255,29 @@ class DICOMwebClient {
12501255
withCredentials = options.withCredentials;
12511256
}
12521257
}
1258+
1259+
let progressCallback = false;
1260+
if ("progressCallback" in options) {
1261+
progressCallback = options.progressCallback;
1262+
}
1263+
12531264
if (!mediaTypes) {
12541265
const responseType = "arraybuffer";
12551266
if (queryParams) {
12561267
url += DICOMwebClient._parseQueryParameters(queryParams);
12571268
}
1258-
return this._httpGet(url, headers, responseType, false, withCredentials);
1269+
return this._httpGet(url, headers, responseType, progressCallback, withCredentials);
12591270
}
12601271

12611272
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
12621273
if (commonMediaType.startsWith("image")) {
1263-
return this._httpGetImage(url, mediaTypes, queryParams, false, withCredentials);
1274+
return this._httpGetImage(url, mediaTypes, queryParams, progressCallback, withCredentials);
12641275
} else if (commonMediaType.startsWith("video")) {
1265-
return this._httpGetVideo(url, mediaTypes, queryParams, false, withCredentials);
1276+
return this._httpGetVideo(url, mediaTypes, queryParams, progressCallback, withCredentials);
12661277
} else if (commonMediaType.startsWith("text")) {
1267-
return this._httpGetText(url, mediaTypes, queryParams, false, withCredentials);
1278+
return this._httpGetText(url, mediaTypes, queryParams, progressCallback, withCredentials);
12681279
} else if (commonMediaType === MEDIATYPES.PDF) {
1269-
return this._httpGetApplicationPdf(url, queryParams, false, withCredentials);
1280+
return this._httpGetApplicationPdf(url, queryParams, progressCallback, withCredentials);
12701281
}
12711282

12721283
throw new Error(
@@ -1314,17 +1325,23 @@ class DICOMwebClient {
13141325
withCredentials = options.withCredentials;
13151326
}
13161327
}
1328+
1329+
let progressCallback = false;
1330+
if ("progressCallback" in options) {
1331+
progressCallback = options.progressCallback;
1332+
}
1333+
13171334
if (!mediaTypes) {
13181335
const responseType = "arraybuffer";
13191336
if (queryParams) {
13201337
url += DICOMwebClient._parseQueryParameters(queryParams);
13211338
}
1322-
return this._httpGet(url, headers, responseType, false, withCredentials);
1339+
return this._httpGet(url, headers, responseType, progressCallback, withCredentials);
13231340
}
13241341

13251342
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
13261343
if (commonMediaType.startsWith("image")) {
1327-
return this._httpGetImage(url, mediaTypes, queryParams, false, withCredentials);
1344+
return this._httpGetImage(url, mediaTypes, queryParams, progressCallback, withCredentials);
13281345
}
13291346

13301347
throw new Error(
@@ -1385,6 +1402,11 @@ class DICOMwebClient {
13851402
withCredentials = options.withCredentials;
13861403
}
13871404
}
1405+
let progressCallback = false;
1406+
if ("progressCallback" in options) {
1407+
progressCallback = options.progressCallback;
1408+
}
1409+
13881410
if (!mediaTypes) {
13891411
const responseType = "arraybuffer";
13901412
if (queryParams) {
@@ -1395,9 +1417,9 @@ class DICOMwebClient {
13951417

13961418
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
13971419
if (commonMediaType.startsWith("image")) {
1398-
return this._httpGetImage(url, mediaTypes, queryParams, false, withCredentials);
1420+
return this._httpGetImage(url, mediaTypes, queryParams, progressCallback, withCredentials);
13991421
} else if (commonMediaType.startsWith("video")) {
1400-
return this._httpGetVideo(url, mediaTypes, queryParams, false, withCredentials);
1422+
return this._httpGetVideo(url, mediaTypes, queryParams, progressCallback, withCredentials);
14011423
}
14021424

14031425
throw new Error(
@@ -1457,17 +1479,23 @@ class DICOMwebClient {
14571479
withCredentials = options.withCredentials;
14581480
}
14591481
}
1482+
1483+
let progressCallback = false;
1484+
if ("progressCallback" in options) {
1485+
progressCallback = options.progressCallback;
1486+
}
1487+
14601488
if (!mediaTypes) {
14611489
const responseType = "arraybuffer";
14621490
if (queryParams) {
14631491
url += DICOMwebClient._parseQueryParameters(queryParams);
14641492
}
1465-
return this._httpGet(url, headers, responseType, false, withCredentials);
1493+
return this._httpGet(url, headers, responseType, progressCallback, withCredentials);
14661494
}
14671495

14681496
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
14691497
if (commonMediaType.startsWith("image")) {
1470-
return this._httpGetImage(url, mediaTypes, queryParams, false, withCredentials);
1498+
return this._httpGetImage(url, mediaTypes, queryParams, progressCallback, withCredentials);
14711499
}
14721500

14731501
throw new Error(
@@ -1505,13 +1533,19 @@ class DICOMwebClient {
15051533
withCredentials = options.withCredentials;
15061534
}
15071535
}
1536+
1537+
let progressCallback = false;
1538+
if ("progressCallback" in options) {
1539+
progressCallback = options.progressCallback;
1540+
}
1541+
15081542
if (!mediaTypes) {
1509-
return this._httpGetMultipartApplicationDicom(url, false, false, false, withCredentials).then(getFirstResult);
1543+
return this._httpGetMultipartApplicationDicom(url, false, false, progressCallback, withCredentials).then(getFirstResult);
15101544
}
15111545

15121546
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
15131547
if (commonMediaType === MEDIATYPES.DICOM) {
1514-
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, false, withCredentials).then(
1548+
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, progressCallback, withCredentials).then(
15151549
getFirstResult
15161550
);
15171551
}
@@ -1548,13 +1582,19 @@ class DICOMwebClient {
15481582
withCredentials = options.withCredentials;
15491583
}
15501584
}
1585+
1586+
let progressCallback = false;
1587+
if ("progressCallback" in options) {
1588+
progressCallback = options.progressCallback;
1589+
}
1590+
15511591
if (!mediaTypes) {
1552-
return this._httpGetMultipartApplicationDicom(url, false, false, false, withCredentials);
1592+
return this._httpGetMultipartApplicationDicom(url, false, false, progressCallback, withCredentials);
15531593
}
15541594

15551595
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
15561596
if (commonMediaType === MEDIATYPES.DICOM) {
1557-
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, false, withCredentials);
1597+
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, progressCallback, withCredentials);
15581598
}
15591599

15601600
throw new Error(
@@ -1583,13 +1623,19 @@ class DICOMwebClient {
15831623
withCredentials = options.withCredentials;
15841624
}
15851625
}
1626+
1627+
let progressCallback = false;
1628+
if ("progressCallback" in options) {
1629+
progressCallback = options.progressCallback;
1630+
}
1631+
15861632
if (!mediaTypes) {
1587-
return this._httpGetMultipartApplicationDicom(url, false, false, false, withCredentials);
1633+
return this._httpGetMultipartApplicationDicom(url, false, false, progressCallback, withCredentials);
15881634
}
15891635

15901636
const commonMediaType = DICOMwebClient._getCommonMediaType(mediaTypes);
15911637
if (commonMediaType === MEDIATYPES.DICOM) {
1592-
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, false, withCredentials);
1638+
return this._httpGetMultipartApplicationDicom(url, mediaTypes, false, progressCallback, withCredentials);
15931639
}
15941640

15951641
throw new Error(
@@ -1621,6 +1667,12 @@ class DICOMwebClient {
16211667
withCredentials = options.withCredentials;
16221668
}
16231669
}
1670+
1671+
let progressCallback = false;
1672+
if ("progressCallback" in options) {
1673+
progressCallback = options.progressCallback;
1674+
}
1675+
16241676
if (!mediaTypes) {
16251677
return this._httpGetMultipartApplicationOctetStream(
16261678
url,
@@ -1637,10 +1689,10 @@ class DICOMwebClient {
16371689
url,
16381690
mediaTypes,
16391691
byteRange,
1640-
false, false, withCredentials
1692+
false, progressCallback, withCredentials
16411693
);
16421694
} else if (commonMediaType.startsWith("image")) {
1643-
return this._httpGetMultipartImage(url, mediaTypes, byteRange, false, false, false, withCredentials);
1695+
return this._httpGetMultipartImage(url, mediaTypes, byteRange, false, false, progressCallback, withCredentials);
16441696
}
16451697

16461698
throw new Error(

0 commit comments

Comments
 (0)