mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
;
This commit is contained in:
parent
dc72f01625
commit
31a6f2d92e
@ -48,38 +48,38 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
|
||||
}
|
||||
|
||||
export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent|SocksProxyAgent {
|
||||
let proxyUrl: string
|
||||
let protocol: string
|
||||
let proxyUrl: string;
|
||||
let protocol: string;
|
||||
|
||||
if (typeof proxy === 'string') {
|
||||
const url = new URL(proxy)
|
||||
protocol = url.protocol.replace(':', '')
|
||||
proxyUrl = proxy
|
||||
const url = new URL(proxy);
|
||||
protocol = url.protocol.replace(':', '');
|
||||
proxyUrl = proxy;
|
||||
} else {
|
||||
const { host, password, port, protocol: proto, username } = proxy
|
||||
protocol = (proto || 'http').replace(':', '')
|
||||
const { host, password, port, protocol: proto, username } = proxy;
|
||||
protocol = (proto || 'http').replace(':', '');
|
||||
|
||||
if (protocol === 'socks') {
|
||||
protocol = 'socks5'
|
||||
protocol = 'socks5';
|
||||
}
|
||||
|
||||
const auth = username && password ? `${username}:${password}@` : ''
|
||||
proxyUrl = `${protocol}://${auth}${host}:${port}`
|
||||
const auth = username && password ? `${username}:${password}@` : '';
|
||||
proxyUrl = `${protocol}://${auth}${host}:${port}`;
|
||||
}
|
||||
|
||||
const PROXY_HTTP_PROTOCOL = 'http'
|
||||
const PROXY_HTTPS_PROTOCOL = 'https'
|
||||
const PROXY_SOCKS4_PROTOCOL = 'socks4'
|
||||
const PROXY_SOCKS5_PROTOCOL = 'socks5'
|
||||
;
|
||||
const PROXY_HTTP_PROTOCOL = 'http';
|
||||
const PROXY_HTTPS_PROTOCOL = 'https';
|
||||
const PROXY_SOCKS4_PROTOCOL = 'socks4';
|
||||
const PROXY_SOCKS5_PROTOCOL = 'socks5';
|
||||
|
||||
switch (protocol) {
|
||||
case PROXY_HTTP_PROTOCOL:
|
||||
case PROXY_HTTPS_PROTOCOL:
|
||||
return new ProxyAgent(proxyUrl)
|
||||
return new ProxyAgent(proxyUrl);
|
||||
case PROXY_SOCKS4_PROTOCOL:
|
||||
case PROXY_SOCKS5_PROTOCOL:
|
||||
return new SocksProxyAgent(proxyUrl)
|
||||
return new SocksProxyAgent(proxyUrl);
|
||||
default:
|
||||
throw new Error(`Unsupported proxy protocol: ${protocol}`)
|
||||
throw new Error(`Unsupported proxy protocol: ${protocol}`);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user