Skip to content

Commit 2d6c05e

Browse files
authored
feat: enhance proxy management and configuration (#8164)
* feat: enhance proxy management and configuration - Added support for new proxy modes and improved proxy configuration handling. - Replaced AxiosProxy with direct axios usage for HTTP requests. - Introduced fetch-socks and undici for better proxy handling. - Updated IPC and ConfigManager to accommodate new proxy settings. - Removed deprecated AxiosProxy service to streamline codebase. * format code * feat: improve proxy configuration and monitoring - Introduced a new mechanism to monitor system proxy changes and update configurations accordingly. - Enhanced the configureProxy method to prevent concurrent executions and added error logging with electron-log. - Refactored proxy handling logic to streamline the setting of global and session proxies. - Removed deprecated methods related to proxy management for cleaner code. * update yarn.lock * fix: update proxy configuration logic to handle direct mode - Modified the app's ready event to check for 'direct' mode before configuring the proxy. - Ensured that the proxy configuration is only applied when necessary, improving efficiency. * feat: enhance proxy configuration to support authentication - Added userId and password fields to the proxy configuration for SOCKS connections. - Improved handling of proxy credentials to allow for authenticated proxy usage. * refactor: remove deprecated proxy methods and streamline configuration logic - Eliminated the setProxy and getProxy methods from ConfigManager to simplify the proxy configuration process. - Updated ProxyManager to initialize with a default proxy configuration and removed unnecessary checks for 'direct' mode during initialization. - Enhanced logging for proxy configuration changes to improve traceability. * format code * feat: enhance WebDav and ProxyManager for self-signed certificate support - Added handling for self-signed certificates in ProxyManager to allow secure connections with custom agents. - Updated WebDav configuration to include an https.Agent with rejectUnauthorized set to false, facilitating connections to servers with self-signed certificates. * delete global setting for rejectUnauthorized
1 parent 8384bbf commit 2d6c05e

File tree

9 files changed

+240
-130
lines changed

9 files changed

+240
-130
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
"eslint-plugin-unused-imports": "^4.1.4",
178178
"fast-diff": "^1.3.0",
179179
"fast-xml-parser": "^5.2.0",
180+
"fetch-socks": "1.3.2",
180181
"franc-min": "^6.2.0",
181182
"fs-extra": "^11.2.0",
182183
"google-auth-library": "^9.15.1",
@@ -229,6 +230,7 @@
229230
"tiny-pinyin": "^1.3.2",
230231
"tokenx": "^1.1.0",
231232
"typescript": "^5.6.2",
233+
"undici": "7.10.0",
232234
"unified": "^11.0.5",
233235
"uuid": "^10.0.0",
234236
"vite": "6.2.6",

src/main/ipc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { handleZoomFactor } from '@main/utils/zoom'
88
import { UpgradeChannel } from '@shared/config/constant'
99
import { IpcChannel } from '@shared/IpcChannel'
1010
import { FileMetadata, Provider, Shortcut, ThemeMode } from '@types'
11-
import { BrowserWindow, dialog, ipcMain, session, shell, systemPreferences, webContents } from 'electron'
11+
import { BrowserWindow, dialog, ipcMain, ProxyConfig, session, shell, systemPreferences, webContents } from 'electron'
1212
import log from 'electron-log'
1313
import { Notification } from 'src/renderer/src/types/notification'
1414

@@ -27,7 +27,7 @@ import MemoryService from './services/memory/MemoryService'
2727
import NotificationService from './services/NotificationService'
2828
import * as NutstoreService from './services/NutstoreService'
2929
import ObsidianVaultService from './services/ObsidianVaultService'
30-
import { ProxyConfig, proxyManager } from './services/ProxyManager'
30+
import { proxyManager } from './services/ProxyManager'
3131
import { pythonService } from './services/PythonService'
3232
import { FileServiceManager } from './services/remotefile/FileServiceManager'
3333
import { searchService } from './services/SearchService'
@@ -78,9 +78,9 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
7878
if (proxy === 'system') {
7979
proxyConfig = { mode: 'system' }
8080
} else if (proxy) {
81-
proxyConfig = { mode: 'custom', url: proxy }
81+
proxyConfig = { mode: 'fixed_servers', proxyRules: proxy }
8282
} else {
83-
proxyConfig = { mode: 'none' }
83+
proxyConfig = { mode: 'direct' }
8484
}
8585

8686
await proxyManager.configureProxy(proxyConfig)

src/main/knowledge/reranker/GeneralReranker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExtractChunkData } from '@cherrystudio/embedjs-interfaces'
2-
import AxiosProxy from '@main/services/AxiosProxy'
32
import { KnowledgeBaseParams } from '@types'
3+
import axios from 'axios'
44

55
import BaseReranker from './BaseReranker'
66

@@ -15,7 +15,7 @@ export default class GeneralReranker extends BaseReranker {
1515
const requestBody = this.getRerankRequestBody(query, searchResults)
1616

1717
try {
18-
const { data } = await AxiosProxy.axios.post(url, requestBody, { headers: this.defaultHeaders() })
18+
const { data } = await axios.post(url, requestBody, { headers: this.defaultHeaders() })
1919

2020
const rerankResults = this.extractRerankResult(data)
2121
return this.getRerankResult(searchResults, rerankResults)

src/main/services/AxiosProxy.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/services/ConfigManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export enum ConfigKeys {
2525
SelectionAssistantRemeberWinSize = 'selectionAssistantRemeberWinSize',
2626
SelectionAssistantFilterMode = 'selectionAssistantFilterMode',
2727
SelectionAssistantFilterList = 'selectionAssistantFilterList',
28-
DisableHardwareAcceleration = 'disableHardwareAcceleration'
28+
DisableHardwareAcceleration = 'disableHardwareAcceleration',
29+
Proxy = 'proxy'
2930
}
3031

3132
export class ConfigManager {

src/main/services/CopilotService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { AxiosRequestConfig } from 'axios'
2+
import axios from 'axios'
23
import { app, safeStorage } from 'electron'
34
import Logger from 'electron-log'
45
import fs from 'fs/promises'
56
import path from 'path'
67

7-
import aoxisProxy from './AxiosProxy'
8-
98
// 配置常量,集中管理
109
const CONFIG = {
1110
GITHUB_CLIENT_ID: 'Iv1.b507a08c87ecfe98',
@@ -96,7 +95,7 @@ class CopilotService {
9695
}
9796
}
9897

99-
const response = await aoxisProxy.axios.get(CONFIG.API_URLS.GITHUB_USER, config)
98+
const response = await axios.get(CONFIG.API_URLS.GITHUB_USER, config)
10099
return {
101100
login: response.data.login,
102101
avatar: response.data.avatar_url
@@ -117,7 +116,7 @@ class CopilotService {
117116
try {
118117
this.updateHeaders(headers)
119118

120-
const response = await aoxisProxy.axios.post<AuthResponse>(
119+
const response = await axios.post<AuthResponse>(
121120
CONFIG.API_URLS.GITHUB_DEVICE_CODE,
122121
{
123122
client_id: CONFIG.GITHUB_CLIENT_ID,
@@ -149,7 +148,7 @@ class CopilotService {
149148
await this.delay(currentDelay)
150149

151150
try {
152-
const response = await aoxisProxy.axios.post<TokenResponse>(
151+
const response = await axios.post<TokenResponse>(
153152
CONFIG.API_URLS.GITHUB_ACCESS_TOKEN,
154153
{
155154
client_id: CONFIG.GITHUB_CLIENT_ID,
@@ -211,7 +210,7 @@ class CopilotService {
211210
}
212211
}
213212

214-
const response = await aoxisProxy.axios.get<CopilotTokenResponse>(CONFIG.API_URLS.COPILOT_TOKEN, config)
213+
const response = await axios.get<CopilotTokenResponse>(CONFIG.API_URLS.COPILOT_TOKEN, config)
215214

216215
return response.data
217216
} catch (error) {

0 commit comments

Comments
 (0)