removed http client for a simple fetch wrapper with logging in utils
This commit is contained in:
parent
89cbfb7848
commit
a07a71d92a
36 changed files with 100 additions and 1465 deletions
|
|
@ -1,18 +1,13 @@
|
|||
/**
|
||||
* Proxy Fetch Operations - Fetching proxies from sources
|
||||
*/
|
||||
import { HttpClient, ProxyInfo } from '@stock-bot/http';
|
||||
import type { ProxyInfo } from '@stock-bot/proxy';
|
||||
import { OperationContext } from '@stock-bot/di';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { fetch } from '@stock-bot/utils';
|
||||
|
||||
import { PROXY_CONFIG } from '../shared/config';
|
||||
import type { ProxySource } from '../shared/types';
|
||||
|
||||
// Shared HTTP client
|
||||
let httpClient: HttpClient;
|
||||
|
||||
function getHttpClient(ctx: OperationContext): HttpClient {
|
||||
if (!httpClient) {
|
||||
httpClient = new HttpClient({ timeout: 10000 }, ctx.logger);
|
||||
}
|
||||
return httpClient;
|
||||
|
|
@ -44,17 +39,17 @@ export async function fetchProxiesFromSource(source: ProxySource, ctx?: Operatio
|
|||
try {
|
||||
ctx.logger.info(`Fetching proxies from ${source.url}`);
|
||||
|
||||
const client = getHttpClient(ctx);
|
||||
const response = await client.get(source.url, {
|
||||
timeout: 10000,
|
||||
});
|
||||
const response = await fetch(source.url, {
|
||||
signal: AbortSignal.timeout(10000),
|
||||
logger: ctx.logger
|
||||
} as any);
|
||||
|
||||
if (response.status !== 200) {
|
||||
if (!response.ok) {
|
||||
ctx.logger.warn(`Failed to fetch from ${source.url}: ${response.status}`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const text = response.data;
|
||||
const text = await response.text();
|
||||
const lines = text.split('\n').filter((line: string) => line.trim());
|
||||
|
||||
for (const line of lines) {
|
||||
|
|
@ -69,7 +64,7 @@ export async function fetchProxiesFromSource(source: ProxySource, ctx?: Operatio
|
|||
if (parts.length >= 2) {
|
||||
const proxy: ProxyInfo = {
|
||||
source: source.id,
|
||||
protocol: source.protocol as 'http' | 'https' | 'socks4' | 'socks5',
|
||||
protocol: source.protocol as 'http' | 'https',
|
||||
host: parts[0],
|
||||
port: parseInt(parts[1]),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue