Skip to content

Commit 0da46f1

Browse files
committed
feat: add isAllProxy field to config
fix: send correct headers to undetect custom app to try bypass captcha
1 parent df65633 commit 0da46f1

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

config.proxy.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// User-Agent: SoundCloud-Desktop/1.0
1111
// [other headers copied as-is]
1212

13+
// проксировать вообще ВСЕ запросы?
14+
// ставьте true если свою проксю юзаете
15+
allProxy: false,
16+
1317
proxy: [
1418
// Add your web proxy URLs here
1519
// "https://cloudflare-proxy-domain.example.com/",

src/modules/ProxyManager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class ProxyManager implements ProxyManagerInterface {
2929
private notifyManager: NotificationManager | null = null;
3030
private httpsAgent: https.Agent;
3131
private httpAgent: http.Agent;
32+
private allProxy: boolean;
3233

3334
// Конфигурация системы strikes
3435
private readonly MAX_STRIKES = 10; // Максимум ошибок подряд
@@ -46,6 +47,12 @@ export class ProxyManager implements ProxyManagerInterface {
4647
this.httpAgent = new http.Agent({
4748
keepAlive: true,
4849
});
50+
51+
this.allProxy = false;
52+
}
53+
54+
static isAllProxy(): boolean {
55+
return ProxyManager.getInstance().allProxy;
4956
}
5057

5158
static getInstance(): ProxyManager {
@@ -103,6 +110,10 @@ export class ProxyManager implements ProxyManagerInterface {
103110
headers: {
104111
...proxy.headers,
105112
...headers,
113+
'user-agent':
114+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
115+
'sec-ch-ua-platform': '"Windows"',
116+
'sec-ch-ua': '"Google Chrome";v="140", "Chromium";v="140", "Not_A Brand";v="24"',
106117
'X-Target': encodedTargetUrl,
107118
},
108119
agent: proxy.protocol === 'https:' ? this.httpsAgent : this.httpAgent,
@@ -157,6 +168,7 @@ export class ProxyManager implements ProxyManagerInterface {
157168
const configManager = ConfigManager.getInstance();
158169
const proxyConfig = configManager.loadProxyConfig();
159170

171+
this.allProxy = proxyConfig.allProxy;
160172
this.allProxies = this.parseProxies(proxyConfig.proxy || []);
161173
this.activeProxies = [...this.allProxies]; // Копируем полный список в активные
162174

@@ -279,7 +291,7 @@ export class ProxyManager implements ProxyManagerInterface {
279291
domain: `${url.protocol}//${url.host}`,
280292
path: url.pathname !== '/' ? url.pathname : undefined,
281293
headers: url.searchParams.has('headers')
282-
? JSON.parse(decodeURIComponent(url.searchParams.get('headers')!))
294+
? JSON.parse(decodeURIComponent(url.searchParams.get('headers') ?? ''))
283295
: undefined,
284296
protocol: url.protocol as 'http:' | 'https:',
285297
// Инициализируем систему strikes

src/modules/WindowSetup.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ export class WindowSetup {
176176

177177
// Устанавливаем User-Agent для всех запросов
178178
headers['User-Agent'] =
179-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36';
180-
headers['sec-ch-ua'] = '"Google Chrome";v="136", "Chromium";v="136", "Not_A Brand";v="24"';
179+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36';
180+
headers['sec-ch-ua'] = '"Google Chrome";v="140", "Chromium";v="140", "Not_A Brand";v="24"';
181+
headers['sec-ch-ua-platform'] = '"Windows"';
181182

182183
callback({ requestHeaders: headers });
183184
} catch (error) {
@@ -190,7 +191,7 @@ export class WindowSetup {
190191
static hookNewWindow(contents: Electron.WebContents): void {
191192
contents.setWindowOpenHandler(({ url }) => {
192193
if (url.startsWith('http')) {
193-
shell.openExternal(url);
194+
void shell.openExternal(url);
194195
return { action: 'deny' };
195196
}
196197
return { action: 'allow' };
@@ -697,6 +698,10 @@ export class WindowSetup {
697698
): Promise<{ shouldProxy: boolean; reason: string }> {
698699
console.debug('shouldProxyDomain.hostname', hostname);
699700

701+
if (ProxyManager.isAllProxy()) {
702+
return { shouldProxy: true, reason: 'enabled all proxying in config' };
703+
}
704+
700705
// Если домен соответствует маскам - сразу проксируем
701706
if (WindowSetup.matchesDomainMask(hostname)) {
702707
console.debug(`Domain ${hostname} matches proxy masks - proxying`);

src/types/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface AppConfig {
4949
}
5050

5151
export interface ProxyConfig {
52+
allProxy: boolean;
5253
proxy: string[];
5354
}
5455

src/utils/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class ConfigManager {
124124
}
125125

126126
if (!configPath) {
127-
return { proxy: [] };
127+
return { proxy: [], allProxy: false };
128128
}
129129

130130
try {
@@ -140,7 +140,7 @@ export class ConfigManager {
140140
return JSON.parse(configContent);
141141
} catch (error) {
142142
console.warn(`Failed to parse proxy config: ${error}`);
143-
return { proxy: [] };
143+
return { proxy: [], allProxy: false };
144144
}
145145
}
146146

0 commit comments

Comments
 (0)