work on proxy

This commit is contained in:
Bojan Kucera 2025-06-08 08:47:44 -04:00
parent d67d07cba6
commit 2f070d73f9
6 changed files with 73 additions and 86 deletions

View file

@ -15,6 +15,7 @@ export class ProxyService {
private readonly CHECK_URL = 'https://proxy-detection.stare.gg/?api_key=bd406bf53ddc6abe1d9de5907830a955';
private readonly PROXY_SOURCES = [
{url: 'https://raw.githubusercontent.com/prxchk/proxy-list/main/http.txt',protocol: 'http', },
{url: 'https://raw.githubusercontent.com/casals-ar/proxy-list/main/http',protocol: 'http', },
{url: 'https://raw.githubusercontent.com/MuRongPIG/Proxy-Master/main/http.txt',protocol: 'http', },
{url: 'https://raw.githubusercontent.com/vakhov/fresh-proxy-list/master/http.txt',protocol: 'http', },
{url: 'https://raw.githubusercontent.com/sunny9577/proxy-scraper/master/proxies.txt',protocol: 'http', },
@ -146,9 +147,7 @@ export class ProxyService {
this.logger.error(`Error fetching proxies from ${source.url}`, error);
return [];
}
this.logger.info(`Total proxies fetched: ${allProxies.length}`);
// this.logger.info(`Total proxies fetched: ${allProxies.length}`);
return allProxies;
}
@ -164,6 +163,10 @@ export class ProxyService {
* Check if a proxy is working
*/
async checkProxy(proxy: ProxyInfo): Promise<ProxyInfo> {
this.logger.debug('Checking Proxy : ', {
host: proxy.host,
port: proxy.port,
});
// console.log('Checking proxy:', `${proxy.protocol}://${proxy.host}:${proxy.port}`, this.concurrencyLimit.activeCount, this.concurrencyLimit.pendingCount);
try {
@ -179,7 +182,8 @@ export class ProxyService {
...proxy,
isWorking,
checkedAt: new Date(),
responseTime: response.responseTime, };
responseTime: response.responseTime,
};
// console.log('Proxy check result:', proxy);
if (isWorking && JSON.stringify(response.data).includes(this.CHECK_IP)) {
await this.cache.set(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`, result, this.CACHE_TTL);