Merge branch 'fix/download-url-agent' into 'develop'
fix: download-url should use proxy bypass hosts Co-authored-by: 老周部落 <laozhoubuluo@gmail.com> See merge request firefish/firefish!10739
This commit is contained in:
commit
280dddf464
2 changed files with 21 additions and 5 deletions
|
@ -2,7 +2,7 @@ import * as fs from "node:fs";
|
|||
import * as stream from "node:stream";
|
||||
import * as util from "node:util";
|
||||
import got, * as Got from "got";
|
||||
import { httpAgent, httpsAgent, StatusError } from "./fetch.js";
|
||||
import { getAgentByHostname, StatusError } from "./fetch.js";
|
||||
import config from "@/config/index.js";
|
||||
import chalk from "chalk";
|
||||
import Logger from "@/services/logger.js";
|
||||
|
@ -40,10 +40,7 @@ export async function downloadUrl(url: string, path: string): Promise<void> {
|
|||
send: timeout,
|
||||
request: operationTimeout, // whole operation timeout
|
||||
},
|
||||
agent: {
|
||||
http: httpAgent,
|
||||
https: httpsAgent,
|
||||
},
|
||||
agent: getAgentByHostname(new URL(url).hostname),
|
||||
http2: false, // default
|
||||
retry: {
|
||||
limit: 0,
|
||||
|
|
|
@ -171,6 +171,25 @@ export function getAgentByUrl(url: URL, bypassProxy = false) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agent by Hostname
|
||||
* @param hostname Hostname
|
||||
* @param bypassProxy Allways bypass proxy
|
||||
*/
|
||||
export function getAgentByHostname(hostname: string, bypassProxy = false) {
|
||||
if (bypassProxy || (config.proxyBypassHosts || []).includes(hostname)) {
|
||||
return {
|
||||
http: _http,
|
||||
https: _https,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
http: httpAgent,
|
||||
https: httpsAgent,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class StatusError extends Error {
|
||||
public statusCode: number;
|
||||
public statusMessage?: string;
|
||||
|
|
Loading…
Reference in a new issue