chore: check script proxy agent supports

This commit is contained in:
GyDi
2022-04-17 00:37:21 +08:00
Unverified
parent ab7313cbc4
commit d83b404fc3
3 changed files with 31 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import zlib from "zlib";
import path from "path";
import AdmZip from "adm-zip";
import fetch from "node-fetch";
import proxyAgent from "https-proxy-agent";
import { execSync } from "child_process";
const cwd = process.cwd();
@@ -153,7 +154,20 @@ async function resolveMmdb() {
async function downloadFile(url, path) {
console.log(`[INFO]: downloading from "${url}"`);
const options = {};
const httpProxy =
process.env.HTTP_PROXY ||
process.env.http_proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy;
if (httpProxy) {
options.agent = proxyAgent(httpProxy);
}
const response = await fetch(url, {
...options,
method: "GET",
headers: { "Content-Type": "application/octet-stream" },
});