@abtnode/util 1.7.26 → 1.7.27
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/lib/axios.js +1 -1
- package/lib/download-file.js +13 -9
- package/package.json +4 -3
package/lib/axios.js
CHANGED
package/lib/download-file.js
CHANGED
|
@@ -7,18 +7,23 @@ const axios = require('./axios');
|
|
|
7
7
|
const CANCEL = '__cancel__';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @param {*} url
|
|
13
|
+
* @param {*} dest directory
|
|
14
|
+
* @param {{
|
|
15
|
+
* timeout: number; // unit: ms
|
|
16
|
+
* cancelCtrl: any;
|
|
17
|
+
* }} [{ timeout = 600 * 1000, cancelCtrl, data }={}]
|
|
18
|
+
* @param {{}} context
|
|
19
|
+
* @return {*}
|
|
15
20
|
*/
|
|
16
|
-
const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}) => {
|
|
21
|
+
const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}, context = {}) => {
|
|
17
22
|
const CONNECTION_TIMEOUT = 20 * 1000;
|
|
18
23
|
const source = CancelToken.source();
|
|
19
24
|
|
|
20
25
|
try {
|
|
21
|
-
|
|
26
|
+
return await tryWithTimeout(async () => {
|
|
22
27
|
const timer = setTimeout(() => {
|
|
23
28
|
source.cancel(`Connection timeout: ${Math.ceil(CONNECTION_TIMEOUT / 1000)}s`);
|
|
24
29
|
}, CONNECTION_TIMEOUT);
|
|
@@ -39,6 +44,7 @@ const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}
|
|
|
39
44
|
|
|
40
45
|
const response = await axios({
|
|
41
46
|
url,
|
|
47
|
+
headers: context?.headers,
|
|
42
48
|
method: 'GET',
|
|
43
49
|
responseType: 'stream',
|
|
44
50
|
cancelToken: source.token,
|
|
@@ -61,8 +67,6 @@ const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}
|
|
|
61
67
|
|
|
62
68
|
return dest;
|
|
63
69
|
}, timeout);
|
|
64
|
-
|
|
65
|
-
return result;
|
|
66
70
|
} catch (err) {
|
|
67
71
|
if (fs.existsSync(dest)) {
|
|
68
72
|
fs.unlinkSync(dest);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.7.
|
|
6
|
+
"version": "1.7.27",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.7.
|
|
21
|
+
"@abtnode/constant": "1.7.27",
|
|
22
22
|
"@ocap/mcrypto": "1.17.0",
|
|
23
23
|
"@ocap/util": "1.17.0",
|
|
24
24
|
"@ocap/wallet": "1.17.0",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"find-up": "^5.0.0",
|
|
31
31
|
"flush-write-stream": "^2.0.0",
|
|
32
32
|
"folder-walker": "^3.2.0",
|
|
33
|
+
"form-data": "^4.0.0",
|
|
33
34
|
"hasha": "^5.2.0",
|
|
34
35
|
"internal-ip": "^6.1.0",
|
|
35
36
|
"is-docker": "^2.1.1",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"fs-extra": "^10.0.1",
|
|
56
57
|
"jest": "^27.4.5"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "81a5492df66389b0aede13f033d1e493450833bc"
|
|
59
60
|
}
|