File tree 3 files changed +136
-54
lines changed
3 files changed +136
-54
lines changed Original file line number Diff line number Diff line change 2
2
3
3
const unzip = require ( 'node-unzip-2' ) ;
4
4
const config = require ( './config' ) ;
5
- const axios = require ( 'axios' ) ;
5
+ const fetch = require ( 'node-fetch' ) ;
6
+ const { HttpsProxyAgent } = require ( 'https-proxy-agent' ) ;
7
+ const { getProxyForUrl } = require ( 'proxy-from-env' ) ;
6
8
7
9
// Downloads the zip file from github and extracts it to folder
8
10
exports . download = ( path ) => {
@@ -11,13 +13,16 @@ exports.download = (path) => {
11
13
// Creating the extractor
12
14
const extractor = unzip . Extract ( { path } ) ;
13
15
14
- let req = axios ( {
15
- method : 'get' ,
16
- url : url ,
17
- responseType : 'stream' ,
18
- headers : { 'User-Agent' : 'tldr-node-client' }
19
- } ) . then ( function ( response ) {
20
- response . data . pipe ( extractor ) ;
16
+ const headers = { 'User-Agent' : 'tldr-node-client' } ;
17
+ const fetchOptions = { headers } ;
18
+
19
+ const proxy = getProxyForUrl ( url ) ;
20
+ if ( proxy ) {
21
+ fetchOptions . agent = new HttpsProxyAgent ( proxy , { headers } ) ;
22
+ }
23
+
24
+ const req = fetch ( url , fetchOptions ) . then ( ( res ) => {
25
+ res . body . pipe ( extractor ) ;
21
26
} ) ;
22
27
23
28
return new Promise ( ( resolve , reject ) => {
Original file line number Diff line number Diff line change 50
50
"test:all" : " npm run lint && npm test && npm run test:functional"
51
51
},
52
52
"dependencies" : {
53
- "axios" : " ^0.21.1" ,
54
53
"chalk" : " ^4.1.0" ,
55
54
"commander" : " ^6.1.0" ,
56
55
"fs-extra" : " ^9.0.1" ,
57
56
"glob" : " ^7.1.6" ,
57
+ "https-proxy-agent" : " ^7.0.2" ,
58
58
"lodash" : " ^4.17.20" ,
59
59
"marked" : " ^4.0.10" ,
60
60
"ms" : " ^2.1.2" ,
61
61
"natural" : " ^2.1.5" ,
62
+ "node-fetch" : " ^2.7.0" ,
62
63
"node-unzip-2" : " ^0.2.8" ,
63
- "ora" : " ^5.1.0"
64
+ "ora" : " ^5.1.0" ,
65
+ "proxy-from-env" : " ^1.1.0"
64
66
},
65
67
"devDependencies" : {
66
68
"eslint" : " ^8.39.0" ,
You can’t perform that action at this time.
0 commit comments