hsu-utils 0.0.34 → 0.0.35
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/es/DownloadFile/index.js
CHANGED
@@ -1,8 +1,27 @@
|
|
1
|
+
function downloadFileByLocalPath(path, fileName) {
|
2
|
+
fetch(path)
|
3
|
+
.then((response) => response.arrayBuffer())
|
4
|
+
.then((arrayBuffer) => {
|
5
|
+
downloadFile(arrayBuffer, fileName);
|
6
|
+
});
|
7
|
+
}
|
1
8
|
function downloadFileByUrl(url, fileName) {
|
9
|
+
if (!url.startsWith('http')) {
|
10
|
+
downloadFileByLocalPath(url, fileName);
|
11
|
+
return;
|
12
|
+
}
|
2
13
|
fetch(url)
|
3
14
|
.then((response) => response.arrayBuffer())
|
4
15
|
.then((arrayBuffer) => {
|
5
16
|
downloadFile(arrayBuffer, fileName);
|
17
|
+
})
|
18
|
+
.catch(() => {
|
19
|
+
const downloadElement = document.createElement('a');
|
20
|
+
downloadElement.href = url;
|
21
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
22
|
+
document.body.appendChild(downloadElement);
|
23
|
+
downloadElement.click();
|
24
|
+
document.body.removeChild(downloadElement);
|
6
25
|
});
|
7
26
|
}
|
8
27
|
export default function downloadFile(file, fileName) {
|
@@ -14,7 +33,7 @@ export default function downloadFile(file, fileName) {
|
|
14
33
|
const downloadElement = document.createElement('a');
|
15
34
|
const href = window.URL.createObjectURL(blob);
|
16
35
|
downloadElement.href = href;
|
17
|
-
downloadElement.download =
|
36
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
18
37
|
document.body.appendChild(downloadElement);
|
19
38
|
downloadElement.click();
|
20
39
|
document.body.removeChild(downloadElement);
|
@@ -1,10 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
function downloadFileByLocalPath(path, fileName) {
|
4
|
+
fetch(path)
|
5
|
+
.then(function (response) { return response.arrayBuffer(); })
|
6
|
+
.then(function (arrayBuffer) {
|
7
|
+
downloadFile(arrayBuffer, fileName);
|
8
|
+
});
|
9
|
+
}
|
3
10
|
function downloadFileByUrl(url, fileName) {
|
11
|
+
if (!url.startsWith('http')) {
|
12
|
+
downloadFileByLocalPath(url, fileName);
|
13
|
+
return;
|
14
|
+
}
|
4
15
|
fetch(url)
|
5
16
|
.then(function (response) { return response.arrayBuffer(); })
|
6
17
|
.then(function (arrayBuffer) {
|
7
18
|
downloadFile(arrayBuffer, fileName);
|
19
|
+
})
|
20
|
+
.catch(function () {
|
21
|
+
var downloadElement = document.createElement('a');
|
22
|
+
downloadElement.href = url;
|
23
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
24
|
+
document.body.appendChild(downloadElement);
|
25
|
+
downloadElement.click();
|
26
|
+
document.body.removeChild(downloadElement);
|
8
27
|
});
|
9
28
|
}
|
10
29
|
function downloadFile(file, fileName) {
|
@@ -16,7 +35,7 @@ function downloadFile(file, fileName) {
|
|
16
35
|
var downloadElement = document.createElement('a');
|
17
36
|
var href = window.URL.createObjectURL(blob);
|
18
37
|
downloadElement.href = href;
|
19
|
-
downloadElement.download =
|
38
|
+
downloadElement.download = decodeURIComponent(fileName || '');
|
20
39
|
document.body.appendChild(downloadElement);
|
21
40
|
downloadElement.click();
|
22
41
|
document.body.removeChild(downloadElement);
|