work on proxy service

This commit is contained in:
Bojan Kucera 2025-06-07 18:04:20 -04:00
parent baa34a3805
commit 81d88357ca
5 changed files with 204 additions and 547 deletions

View file

@ -2,20 +2,20 @@ import got from 'got';
import { SocksProxyAgent } from 'socks-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { HttpProxyAgent } from 'http-proxy-agent';
import type { ProxyConfig } from './types.js';
import type { ProxyInfo } from './types.js';
export class ProxyManager {
/**
* Determine if we should use Bun fetch (HTTP/HTTPS) or Got (SOCKS)
*/
static shouldUseBunFetch(proxy: ProxyConfig): boolean {
static shouldUseBunFetch(proxy: ProxyInfo): boolean {
return proxy.protocol === 'http' || proxy.protocol === 'https';
}
/**
* Create Bun fetch proxy URL for HTTP/HTTPS proxies
*/
static createBunProxyUrl(proxy: ProxyConfig): string {
static createBunProxyUrl(proxy: ProxyInfo): string {
const { protocol, host, port, username, password } = proxy;
if (username && password) {
@ -27,7 +27,7 @@ export class ProxyManager {
/**
* Create appropriate agent for Got based on proxy type
*/
static createGotAgent(proxy: ProxyConfig) {
static createGotAgent(proxy: ProxyInfo) {
this.validateConfig(proxy);
const proxyUrl = this.buildProxyUrl(proxy);
@ -48,7 +48,7 @@ export class ProxyManager {
/**
* Create Got instance with proxy configuration
*/
static createGotInstance(proxy: ProxyConfig) {
static createGotInstance(proxy: ProxyInfo) {
const agent = this.createGotAgent(proxy);
return got.extend({
@ -68,7 +68,7 @@ export class ProxyManager {
});
}
private static buildProxyUrl(proxy: ProxyConfig): string {
private static buildProxyUrl(proxy: ProxyInfo): string {
const { protocol, host, port, username, password } = proxy;
if (username && password) {
@ -80,7 +80,7 @@ export class ProxyManager {
/**
* Simple proxy config validation
*/
static validateConfig(proxy: ProxyConfig): void {
static validateConfig(proxy: ProxyInfo): void {
if (!proxy.host || !proxy.port) {
throw new Error('Proxy host and port are required');
}