mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-11 19:09:39 -06:00
Merge branch 'main' of https://github.com/RaFaeL-Cunha/evolution-api
This commit is contained in:
commit
c34d120336
10
package-lock.json
generated
10
package-lock.json
generated
@ -65,6 +65,7 @@
|
|||||||
"socks-proxy-agent": "^8.0.5",
|
"socks-proxy-agent": "^8.0.5",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"tsup": "^8.3.5",
|
"tsup": "^8.3.5",
|
||||||
|
"undici": "^7.16.0",
|
||||||
"uuid": "^13.0.0"
|
"uuid": "^13.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -15480,6 +15481,15 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/undici": {
|
||||||
|
"version": "7.16.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici/-/undici-7.16.0.tgz",
|
||||||
|
"integrity": "sha512-QEg3HPMll0o3t2ourKwOeUAZ159Kn9mx5pnzHRQO8+Wixmh88YdZRiIwat0iNzNNXn0yoEtXJqFpyW7eM8BV7g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.18.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "7.16.0",
|
"version": "7.16.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||||
|
|||||||
@ -121,6 +121,7 @@
|
|||||||
"socks-proxy-agent": "^8.0.5",
|
"socks-proxy-agent": "^8.0.5",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"tsup": "^8.3.5",
|
"tsup": "^8.3.5",
|
||||||
|
"undici": "^7.16.0",
|
||||||
"uuid": "^13.0.0"
|
"uuid": "^13.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||||
import { SocksProxyAgent } from 'socks-proxy-agent';
|
import { SocksProxyAgent } from 'socks-proxy-agent';
|
||||||
|
|
||||||
|
import { ProxyAgent } from 'undici'
|
||||||
|
|
||||||
type Proxy = {
|
type Proxy = {
|
||||||
host: string;
|
host: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
@ -42,3 +44,40 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
|
|||||||
|
|
||||||
return selectProxyAgent(proxyUrl);
|
return selectProxyAgent(proxyUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent {
|
||||||
|
let proxyUrl: string
|
||||||
|
let protocol: string
|
||||||
|
|
||||||
|
if (typeof proxy === 'string') {
|
||||||
|
const url = new URL(proxy)
|
||||||
|
protocol = url.protocol.replace(':', '')
|
||||||
|
proxyUrl = proxy
|
||||||
|
} else {
|
||||||
|
const { host, password, port, protocol: proto, username } = proxy
|
||||||
|
protocol = (proto || 'http').replace(':', '')
|
||||||
|
|
||||||
|
if (protocol === 'socks') {
|
||||||
|
protocol = 'socks5'
|
||||||
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
switch (protocol) {
|
||||||
|
case PROXY_HTTP_PROTOCOL:
|
||||||
|
case PROXY_HTTPS_PROTOCOL:
|
||||||
|
case PROXY_SOCKS4_PROTOCOL:
|
||||||
|
case PROXY_SOCKS5_PROTOCOL:
|
||||||
|
return new ProxyAgent(proxyUrl)
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported proxy protocol: ${protocol}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user