mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-11 10:59:37 -06:00
socks
This commit is contained in:
parent
d3e3c458a0
commit
ea88edd512
11
package-lock.json
generated
11
package-lock.json
generated
@ -31,6 +31,7 @@
|
|||||||
"eventemitter2": "^6.4.9",
|
"eventemitter2": "^6.4.9",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-async-errors": "^3.1.1",
|
"express-async-errors": "^3.1.1",
|
||||||
|
"fetch-socks": "^1.3.2",
|
||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"https-proxy-agent": "^7.0.6",
|
"https-proxy-agent": "^7.0.6",
|
||||||
@ -8628,6 +8629,16 @@
|
|||||||
"reusify": "^1.0.4"
|
"reusify": "^1.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fetch-socks": {
|
||||||
|
"version": "1.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fetch-socks/-/fetch-socks-1.3.2.tgz",
|
||||||
|
"integrity": "sha512-vkH5+Zgj2yEbU57Cei0iyLgTZ4OkEKJj56Xu3ViB5dpsl599JgEooQ3x6NVagIFRHWnWJ+7K0MO0aIV1TMgvnw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"socks": "^2.8.2",
|
||||||
|
"undici": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fflate": {
|
"node_modules/fflate": {
|
||||||
"version": "0.8.2",
|
"version": "0.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
|
||||||
|
|||||||
@ -90,6 +90,7 @@
|
|||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"https-proxy-agent": "^7.0.6",
|
"https-proxy-agent": "^7.0.6",
|
||||||
|
"fetch-socks": "^1.3.2",
|
||||||
"i18next": "^23.7.19",
|
"i18next": "^23.7.19",
|
||||||
"jimp": "^1.6.0",
|
"jimp": "^1.6.0",
|
||||||
"json-schema": "^0.4.0",
|
"json-schema": "^0.4.0",
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { socksDispatcher } from 'fetch-socks';
|
||||||
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';
|
import { ProxyAgent } from 'undici';
|
||||||
@ -46,7 +47,7 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
|
|||||||
return selectProxyAgent(proxyUrl);
|
return selectProxyAgent(proxyUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksProxyAgent {
|
export function makeProxyAgentUndici(proxy: Proxy | string) {
|
||||||
let proxyUrl: string;
|
let proxyUrl: string;
|
||||||
let protocol: string;
|
let protocol: string;
|
||||||
|
|
||||||
@ -57,15 +58,15 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP
|
|||||||
} else {
|
} else {
|
||||||
const { host, password, port, protocol: proto, username } = proxy;
|
const { host, password, port, protocol: proto, username } = proxy;
|
||||||
protocol = (proto || 'http').replace(':', '');
|
protocol = (proto || 'http').replace(':', '');
|
||||||
|
if (protocol === 'socks') protocol = 'socks5';
|
||||||
if (protocol === 'socks') {
|
|
||||||
protocol = 'socks5';
|
|
||||||
}
|
|
||||||
|
|
||||||
const auth = username && password ? `${username}:${password}@` : '';
|
const auth = username && password ? `${username}:${password}@` : '';
|
||||||
proxyUrl = `${protocol}://${auth}${host}:${port}`;
|
proxyUrl = `${protocol}://${auth}${host}:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalização
|
||||||
|
protocol = protocol.toLowerCase();
|
||||||
|
|
||||||
const PROXY_HTTP_PROTOCOL = 'http';
|
const PROXY_HTTP_PROTOCOL = 'http';
|
||||||
const PROXY_HTTPS_PROTOCOL = 'https';
|
const PROXY_HTTPS_PROTOCOL = 'https';
|
||||||
const PROXY_SOCKS4_PROTOCOL = 'socks4';
|
const PROXY_SOCKS4_PROTOCOL = 'socks4';
|
||||||
@ -74,10 +75,26 @@ export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent | SocksP
|
|||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case PROXY_HTTP_PROTOCOL:
|
case PROXY_HTTP_PROTOCOL:
|
||||||
case PROXY_HTTPS_PROTOCOL:
|
case PROXY_HTTPS_PROTOCOL:
|
||||||
|
// Proxy HTTP/HTTPS → usar ProxyAgent do Undici
|
||||||
return new ProxyAgent(proxyUrl);
|
return new ProxyAgent(proxyUrl);
|
||||||
|
|
||||||
case PROXY_SOCKS4_PROTOCOL:
|
case PROXY_SOCKS4_PROTOCOL:
|
||||||
case PROXY_SOCKS5_PROTOCOL:
|
case PROXY_SOCKS5_PROTOCOL: {
|
||||||
return new SocksProxyAgent(proxyUrl);
|
let type: 4 | 5 = 5;
|
||||||
|
|
||||||
|
if (PROXY_SOCKS4_PROTOCOL === protocol) type = 4;
|
||||||
|
|
||||||
|
const url = new URL(proxyUrl);
|
||||||
|
|
||||||
|
return socksDispatcher({
|
||||||
|
type: type,
|
||||||
|
host: url.hostname,
|
||||||
|
port: Number(url.port),
|
||||||
|
userId: url.username || undefined,
|
||||||
|
password: url.password || undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported proxy protocol: ${protocol}`);
|
throw new Error(`Unsupported proxy protocol: ${protocol}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user