File tree Expand file tree Collapse file tree 3 files changed +136
-54
lines changed Expand file tree Collapse file tree 3 files changed +136
-54
lines changed Original file line number Diff line number Diff line change 22
33const unzip = require ( 'node-unzip-2' ) ;
44const 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' ) ;
68
79// Downloads the zip file from github and extracts it to folder
810exports . download = ( path ) => {
@@ -11,13 +13,16 @@ exports.download = (path) => {
1113 // Creating the extractor
1214 const extractor = unzip . Extract ( { path } ) ;
1315
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 ) ;
2126 } ) ;
2227
2328 return new Promise ( ( resolve , reject ) => {
Original file line number Diff line number Diff line change 5050 "test:all" : " npm run lint && npm test && npm run test:functional"
5151 },
5252 "dependencies" : {
53- "axios" : " ^0.21.1" ,
5453 "chalk" : " ^4.1.0" ,
5554 "commander" : " ^6.1.0" ,
5655 "fs-extra" : " ^9.0.1" ,
5756 "glob" : " ^7.1.6" ,
57+ "https-proxy-agent" : " ^7.0.2" ,
5858 "lodash" : " ^4.17.20" ,
5959 "marked" : " ^4.0.10" ,
6060 "ms" : " ^2.1.2" ,
6161 "natural" : " ^2.1.5" ,
62+ "node-fetch" : " ^2.7.0" ,
6263 "node-unzip-2" : " ^0.2.8" ,
63- "ora" : " ^5.1.0"
64+ "ora" : " ^5.1.0" ,
65+ "proxy-from-env" : " ^1.1.0"
6466 },
6567 "devDependencies" : {
6668 "eslint" : " ^8.39.0" ,
You can’t perform that action at this time.
0 commit comments