Merge branch 'main' into bugfix/waiting-for-message

This commit is contained in:
Jeferson Ramos
2025-11-05 16:27:22 -03:00
4 changed files with 53 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ import { createId as cuid } from '@paralleldrive/cuid2';
import { Instance, Message } from '@prisma/client';
import { createJid } from '@utils/createJid';
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
import { makeProxyAgent } from '@utils/makeProxyAgent';
import {makeProxyAgent, makeProxyAgentUndici} from '@utils/makeProxyAgent';
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
import { status } from '@utils/renderStatus';
import { sendTelemetry } from '@utils/sendTelemetry';
@@ -616,7 +616,7 @@ export class BaileysStartupService extends ChannelStartupService {
const proxyUrls = text.split('\r\n');
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
const proxyUrl = 'http://' + proxyUrls[rand];
options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgent(proxyUrl) };
options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgentUndici(proxyUrl) };
} catch {
this.localProxy.enabled = false;
}
@@ -629,7 +629,7 @@ export class BaileysStartupService extends ChannelStartupService {
username: this.localProxy.username,
password: this.localProxy.password,
}),
fetchAgent: makeProxyAgent({
fetchAgent: makeProxyAgentUndici({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,

View File

@@ -1,6 +1,8 @@
import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';
import { ProxyAgent } from 'undici'
type Proxy = {
host: string;
password?: string;
@@ -42,3 +44,40 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
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}`)
}
}