Skip to content

Commit

Permalink
fix: Update command does not work with proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
code2933 committed Oct 20, 2023
1 parent cb63e51 commit e7fee41
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 54 deletions.
21 changes: 13 additions & 8 deletions lib/remote.js
Expand Up @@ -2,7 +2,9 @@

const unzip = require('node-unzip-2');
const config = require('./config');
const axios = require('axios');
const fetch = require('node-fetch');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { getProxyForUrl } = require('proxy-from-env');

// Downloads the zip file from github and extracts it to folder
exports.download = (path) => {
Expand All @@ -11,13 +13,16 @@ exports.download = (path) => {
// Creating the extractor
const extractor = unzip.Extract({ path });

let req = axios({
method: 'get',
url: url,
responseType: 'stream',
headers: { 'User-Agent' : 'tldr-node-client' }
}).then(function (response) {
response.data.pipe(extractor);
const headers = { 'User-Agent' : 'tldr-node-client' };
const fetchOptions = { headers };

const proxy = getProxyForUrl(url);
if (proxy) {
fetchOptions.agent = new HttpsProxyAgent(proxy, { headers });
}

const req = fetch(url, fetchOptions).then((res) => {
res.body.pipe(extractor);
});

return new Promise((resolve, reject) => {
Expand Down
163 changes: 119 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -50,17 +50,19 @@
"test:all": "npm run lint && npm test && npm run test:functional"
},
"dependencies": {
"axios": "^0.21.1",
"chalk": "^4.1.0",
"commander": "^6.1.0",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"https-proxy-agent": "^7.0.2",
"lodash": "^4.17.20",
"marked": "^4.0.10",
"ms": "^2.1.2",
"natural": "^2.1.5",
"node-fetch": "^2.7.0",
"node-unzip-2": "^0.2.8",
"ora": "^5.1.0"
"ora": "^5.1.0",
"proxy-from-env": "^1.1.0"
},
"devDependencies": {
"eslint": "^8.39.0",
Expand Down

0 comments on commit e7fee41

Please sign in to comment.