hsu-utils 0.0.38 → 0.0.39
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 +1 -1
- package/dist/hsu-utils.js +2 -2
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/DownloadFile/index.js +9 -7
- package/lib/DownloadFile/index.js +15 -13
- package/package.json +1 -1
package/es/DownloadFile/index.js
CHANGED
@@ -15,13 +15,15 @@ function downloadFileByUrl(url, fileName, signal) {
|
|
15
15
|
const arrayBuffer = yield response.arrayBuffer();
|
16
16
|
downloadFile(arrayBuffer, fileName);
|
17
17
|
}
|
18
|
-
catch (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
catch (error) {
|
19
|
+
if ((error === null || error === void 0 ? void 0 : error.name) !== 'AbortError') {
|
20
|
+
const downloadElement = document.createElement('a');
|
21
|
+
downloadElement.href = url;
|
22
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
23
|
+
document.body.appendChild(downloadElement);
|
24
|
+
downloadElement.click();
|
25
|
+
document.body.removeChild(downloadElement);
|
26
|
+
}
|
25
27
|
}
|
26
28
|
});
|
27
29
|
}
|
@@ -39,27 +39,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var __1 = require("..");
|
40
40
|
function downloadFileByUrl(url, fileName, signal) {
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
42
|
-
var response, arrayBuffer,
|
43
|
-
return __generator(this, function (
|
44
|
-
switch (
|
42
|
+
var response, arrayBuffer, error_1, downloadElement;
|
43
|
+
return __generator(this, function (_a) {
|
44
|
+
switch (_a.label) {
|
45
45
|
case 0:
|
46
|
-
|
46
|
+
_a.trys.push([0, 3, , 4]);
|
47
47
|
return [4, fetch(url, { signal: signal })];
|
48
48
|
case 1:
|
49
|
-
response =
|
49
|
+
response = _a.sent();
|
50
50
|
return [4, response.arrayBuffer()];
|
51
51
|
case 2:
|
52
|
-
arrayBuffer =
|
52
|
+
arrayBuffer = _a.sent();
|
53
53
|
downloadFile(arrayBuffer, fileName);
|
54
54
|
return [3, 4];
|
55
55
|
case 3:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
error_1 = _a.sent();
|
57
|
+
if ((error_1 === null || error_1 === void 0 ? void 0 : error_1.name) !== 'AbortError') {
|
58
|
+
downloadElement = document.createElement('a');
|
59
|
+
downloadElement.href = url;
|
60
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
61
|
+
document.body.appendChild(downloadElement);
|
62
|
+
downloadElement.click();
|
63
|
+
document.body.removeChild(downloadElement);
|
64
|
+
}
|
63
65
|
return [3, 4];
|
64
66
|
case 4: return [2];
|
65
67
|
}
|