@bbn/bbn 1.0.81 → 1.0.82
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/dist/bundle.js +12 -9
- package/dist/fn/ajax/download.js +18 -15
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -5005,15 +5005,16 @@
|
|
|
5005
5005
|
*/
|
|
5006
5006
|
const download = function (url, filename, params) {
|
|
5007
5007
|
// We can intervert the arguments
|
|
5008
|
-
if (filename &&
|
|
5008
|
+
if (filename && typeof filename === "object") {
|
|
5009
5009
|
params = filename;
|
|
5010
|
-
filename =
|
|
5010
|
+
filename = "";
|
|
5011
5011
|
}
|
|
5012
|
-
return (0, ajax_1.ajax)(url,
|
|
5012
|
+
return (0, ajax_1.ajax)(url, "blob", params || { _bbn_download: 1 }, (d, headers) => {
|
|
5013
5013
|
if (!filename) {
|
|
5014
|
-
let
|
|
5015
|
-
|
|
5016
|
-
|
|
5014
|
+
let prop = "content-disposition";
|
|
5015
|
+
let cd = "attachment; filename=";
|
|
5016
|
+
if ((headers === null || headers === void 0 ? void 0 : headers[prop]) && headers[prop].indexOf(cd) === 0) {
|
|
5017
|
+
filename = (0, substr_7.substr)(headers[prop], cd.length + 1, headers[prop].length - cd.length - 2);
|
|
5017
5018
|
}
|
|
5018
5019
|
else {
|
|
5019
5020
|
filename = (0, baseName_1.baseName)(url);
|
|
@@ -5021,13 +5022,15 @@
|
|
|
5021
5022
|
}
|
|
5022
5023
|
if ((0, isBlob_1.isBlob)(d)) {
|
|
5023
5024
|
let extension = (0, fileExt_1.fileExt)(filename);
|
|
5024
|
-
let htmlExtensions = [
|
|
5025
|
-
if (
|
|
5025
|
+
let htmlExtensions = ["php", "html"];
|
|
5026
|
+
if (typeof filename === "string" &&
|
|
5027
|
+
(("type" in d && d.type !== "text/html") ||
|
|
5028
|
+
htmlExtensions.includes(extension))) {
|
|
5026
5029
|
(0, downloadContent_1.downloadContent)(filename, d);
|
|
5027
5030
|
return;
|
|
5028
5031
|
}
|
|
5029
5032
|
}
|
|
5030
|
-
}, e => {
|
|
5033
|
+
}, (e) => {
|
|
5031
5034
|
bbn.fn.defaultAjaxErrorFunction(e);
|
|
5032
5035
|
});
|
|
5033
5036
|
};
|
package/dist/fn/ajax/download.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ajax } from
|
|
2
|
-
import { substr } from
|
|
3
|
-
import { baseName } from
|
|
4
|
-
import { isBlob } from
|
|
5
|
-
import { fileExt } from
|
|
6
|
-
import { downloadContent } from
|
|
1
|
+
import { ajax } from "./ajax";
|
|
2
|
+
import { substr } from "../string/substr";
|
|
3
|
+
import { baseName } from "../string/baseName";
|
|
4
|
+
import { isBlob } from "../type/isBlob";
|
|
5
|
+
import { fileExt } from "../string/fileExt";
|
|
6
|
+
import { downloadContent } from "./downloadContent";
|
|
7
7
|
/**
|
|
8
8
|
* Downloads a file with given filename from a URL.
|
|
9
9
|
*
|
|
@@ -34,15 +34,16 @@ import { downloadContent } from './downloadContent';
|
|
|
34
34
|
*/
|
|
35
35
|
const download = function (url, filename, params) {
|
|
36
36
|
// We can intervert the arguments
|
|
37
|
-
if (filename &&
|
|
37
|
+
if (filename && typeof filename === "object") {
|
|
38
38
|
params = filename;
|
|
39
|
-
filename =
|
|
39
|
+
filename = "";
|
|
40
40
|
}
|
|
41
|
-
return ajax(url,
|
|
41
|
+
return ajax(url, "blob", params || { _bbn_download: 1 }, (d, headers) => {
|
|
42
42
|
if (!filename) {
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
let prop = "content-disposition";
|
|
44
|
+
let cd = "attachment; filename=";
|
|
45
|
+
if ((headers === null || headers === void 0 ? void 0 : headers[prop]) && headers[prop].indexOf(cd) === 0) {
|
|
46
|
+
filename = substr(headers[prop], cd.length + 1, headers[prop].length - cd.length - 2);
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
49
|
filename = baseName(url);
|
|
@@ -50,13 +51,15 @@ const download = function (url, filename, params) {
|
|
|
50
51
|
}
|
|
51
52
|
if (isBlob(d)) {
|
|
52
53
|
let extension = fileExt(filename);
|
|
53
|
-
let htmlExtensions = [
|
|
54
|
-
if (
|
|
54
|
+
let htmlExtensions = ["php", "html"];
|
|
55
|
+
if (typeof filename === "string" &&
|
|
56
|
+
(("type" in d && d.type !== "text/html") ||
|
|
57
|
+
htmlExtensions.includes(extension))) {
|
|
55
58
|
downloadContent(filename, d);
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
|
-
}, e => {
|
|
62
|
+
}, (e) => {
|
|
60
63
|
bbn.fn.defaultAjaxErrorFunction(e);
|
|
61
64
|
});
|
|
62
65
|
};
|