mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-01-11 06:12:19 -06:00
Merge pull request #374 from judsonjuniorr/proxy-improvements
Proxy improvements
This commit is contained in:
@@ -45,7 +45,6 @@ import { getMIMEType } from 'node-mime-types';
|
||||
import { release } from 'os';
|
||||
import { join } from 'path';
|
||||
import P from 'pino';
|
||||
import { ProxyAgent } from 'proxy-agent';
|
||||
import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
||||
import qrcodeTerminal from 'qrcode-terminal';
|
||||
import sharp from 'sharp';
|
||||
@@ -73,6 +72,7 @@ import { dbserver } from '../../libs/db.connect';
|
||||
import { RedisCache } from '../../libs/redis.client';
|
||||
import { getIO } from '../../libs/socket.server';
|
||||
import { getSQS, removeQueues as removeQueuesSQS } from '../../libs/sqs.server';
|
||||
import { makeProxyAgent } from '../../utils/makeProxyAgent';
|
||||
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
|
||||
import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db';
|
||||
import {
|
||||
@@ -1385,24 +1385,21 @@ export class WAStartupService {
|
||||
this.logger.info('Proxy enabled: ' + this.localProxy.proxy);
|
||||
|
||||
if (this.localProxy.proxy.host.includes('proxyscrape')) {
|
||||
const response = await axios.get(this.localProxy.proxy.host);
|
||||
const text = response.data;
|
||||
const proxyUrls = text.split('\r\n');
|
||||
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
|
||||
const proxyUrl = 'http://' + proxyUrls[rand];
|
||||
options = {
|
||||
agent: new ProxyAgent(proxyUrl as any),
|
||||
};
|
||||
} else {
|
||||
let proxyUri =
|
||||
this.localProxy.proxy.protocol + '://' + this.localProxy.proxy.host + ':' + this.localProxy.proxy.port;
|
||||
|
||||
if (this.localProxy.proxy.username && this.localProxy.proxy.password) {
|
||||
proxyUri = `${this.localProxy.proxy.username}:${this.localProxy.proxy.password}@${proxyUri}`;
|
||||
try {
|
||||
const response = await axios.get(this.localProxy.proxy.host);
|
||||
const text = response.data;
|
||||
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),
|
||||
};
|
||||
} catch (error) {
|
||||
this.localProxy.enabled = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
options = {
|
||||
agent: new ProxyAgent(proxyUri as any),
|
||||
agent: makeProxyAgent(this.localProxy.proxy),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1489,8 +1486,8 @@ export class WAStartupService {
|
||||
if (this.localProxy.enabled) {
|
||||
this.logger.verbose('Proxy enabled');
|
||||
options = {
|
||||
agent: new ProxyAgent(this.localProxy.proxy as any),
|
||||
fetchAgent: new ProxyAgent(this.localProxy.proxy as any),
|
||||
agent: makeProxyAgent(this.localProxy.proxy),
|
||||
fetchAgent: makeProxyAgent(this.localProxy.proxy),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user