refactor(utils): lint

This commit is contained in:
ricael 2025-10-30 16:36:01 -03:00
parent a95c843e77
commit 3b0432dd9f
2 changed files with 18 additions and 19 deletions

View File

@ -82,7 +82,7 @@ import { createId as cuid } from '@paralleldrive/cuid2';
import { Instance, Message } from '@prisma/client'; import { Instance, Message } from '@prisma/client';
import { createJid } from '@utils/createJid'; import { createJid } from '@utils/createJid';
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion'; import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
import {makeProxyAgent, makeProxyAgentUndici} from '@utils/makeProxyAgent'; import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache'; import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
import { status } from '@utils/renderStatus'; import { status } from '@utils/renderStatus';
import { sendTelemetry } from '@utils/sendTelemetry'; import { sendTelemetry } from '@utils/sendTelemetry';

View File

@ -1,7 +1,6 @@
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'
type Proxy = { type Proxy = {
host: string; host: string;
@ -46,38 +45,38 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> |
} }
export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent {
let proxyUrl: string let proxyUrl: string;
let protocol: string let protocol: string;
if (typeof proxy === 'string') { if (typeof proxy === 'string') {
const url = new URL(proxy) const url = new URL(proxy);
protocol = url.protocol.replace(':', '') protocol = url.protocol.replace(':', '');
proxyUrl = proxy proxyUrl = proxy;
} 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') { if (protocol === 'socks') {
protocol = 'socks5' protocol = 'socks5';
} }
const auth = username && password ? `${username}:${password}@` : '' const auth = username && password ? `${username}:${password}@` : '';
proxyUrl = `${protocol}://${auth}${host}:${port}` proxyUrl = `${protocol}://${auth}${host}:${port}`;
} }
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';
const PROXY_SOCKS5_PROTOCOL = 'socks5' const PROXY_SOCKS5_PROTOCOL = 'socks5';
switch (protocol) { switch (protocol) {
case PROXY_HTTP_PROTOCOL: case PROXY_HTTP_PROTOCOL:
case PROXY_HTTPS_PROTOCOL: case PROXY_HTTPS_PROTOCOL:
case PROXY_SOCKS4_PROTOCOL: case PROXY_SOCKS4_PROTOCOL:
case PROXY_SOCKS5_PROTOCOL: case PROXY_SOCKS5_PROTOCOL:
return new ProxyAgent(proxyUrl) return new ProxyAgent(proxyUrl);
default: default:
throw new Error(`Unsupported proxy protocol: ${protocol}`) throw new Error(`Unsupported proxy protocol: ${protocol}`);
} }
} }