Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🌐 chore: translate non-English comments to English in networkProxy (#10293)

LobeHub Bote8c7d1c5685f
diff --git a/apps/desktop/src/main/modules/networkProxy/dispatcher.ts b/apps/desktop/src/main/modules/networkProxy/dispatcher.ts
index 5457f7e9414..1374b828187 100644
--- a/apps/desktop/src/main/modules/networkProxy/dispatcher.ts
+++ b/apps/desktop/src/main/modules/networkProxy/dispatcher.ts
@@ -10,14 +10,14 @@ import { ProxyUrlBuilder } from './urlBuilder';
const logger = createLogger('modules:networkProxy:dispatcher');
/**
- * 代理管理器
+ * Proxy dispatcher manager
*/
export class ProxyDispatcherManager {
private static isChanging = false;
private static changeQueue: Array<() => Promise<void>> = [];
/**
- * 应用代理设置(带并发控制)
+ * Apply proxy settings (with concurrency control)
*/
static async applyProxySettings(config: NetworkProxySettings): Promise<void> {
return new Promise((resolve, reject) => {
@@ -31,17 +31,17 @@ export class ProxyDispatcherManager {
};
if (this.isChanging) {
- // 如果正在切换,加入队列
+ // If currently switching, add to queue
this.changeQueue.push(operation);
} else {
- // 立即执行
+ // Execute immediately
operation();
}
});
}
/**
- * 执行代理设置应用
+ * Execute proxy settings application
*/
private static async doApplyProxySettings(config: NetworkProxySettings): Promise<void> {
this.isChanging = true;
@@ -49,22 +49,22 @@ export class ProxyDispatcherManager {
try {
const currentDispatcher = getGlobalDispatcher();
- // 禁用代理,恢复默认连接
+ // Disable proxy, restore default connection
if (!config.enableProxy) {
await this.safeDestroyDispatcher(currentDispatcher);
- // 创建一个新的默认 Agent 来替代代理
+ // Create a new default Agent to replace the proxy
setGlobalDispatcher(new Agent());
logger.debug('Proxy disabled, reset to direct connection mode');
return;
}
- // 构建代理 URL
+ // Build proxy URL
const proxyUrl = ProxyUrlBuilder.build(config);
- // 创建代理 agent
+ // Create proxy agent
const agent = this.createProxyAgent(config.proxyType, proxyUrl);
- // 切换代理前销毁旧 dispatcher
+ // Destroy old dispatcher before switching proxy
await this.safeDestroyDispatcher(currentDispatcher);
setGlobalDispatcher(agent);
@@ -77,7 +77,7 @@ export class ProxyDispatcherManager {
} finally {
this.isChanging = false;
- // 处理队列中的下一个操作
+ // Process next operation in queue
if (this.changeQueue.length > 0) {
const nextOperation = this.changeQueue.shift();
if (nextOperation) {
@@ -88,12 +88,12 @@ export class ProxyDispatcherManager {
}
/**
- * 创建代理 agent
+ * Create proxy agent
*/
static createProxyAgent(proxyType: string, proxyUrl: string) {
try {
if (proxyType === 'socks5') {
- // 解析 SOCKS5 代理 URL
+ // Parse SOCKS5 proxy URL
const url = new URL(proxyUrl);
const socksProxies: SocksProxies = [
{
@@ -109,10 +109,10 @@ export class ProxyDispatcherManager {
},
];
- // 使用 fetch-socks 处理 SOCKS5 代理
+ // Use fetch-socks to handle SOCKS5 proxy
return socksDispatcher(socksProxies);
} else {
- // undici 的 ProxyAgent 支持 http, https
+ // undici's ProxyAgent supports http, https
return new ProxyAgent({ uri: proxyUrl });
}
} catch (error) {
@@ -124,7 +124,7 @@ export class ProxyDispatcherManager {
}
/**
- * 安全销毁 dispatcher
+ * Safely destroy dispatcher
*/
private static async safeDestroyDispatcher(dispatcher: any): Promise<void> {
try {
diff --git a/apps/desktop/src/main/modules/networkProxy/tester.ts b/apps/desktop/src/main/modules/networkProxy/tester.ts
index e14ef6606da..257458e11ce 100644
--- a/apps/desktop/src/main/modules/networkProxy/tester.ts
+++ b/apps/desktop/src/main/modules/networkProxy/tester.ts
@@ -11,7 +11,7 @@ import { ProxyConfigValidator } from './validator';
const logger = createLogger('modules:networkProxy:tester');
/**
- * 代理连接测试结果
+ * Proxy connection test result
*/
export interface ProxyTestResult {
message?: string;
@@ -20,14 +20,14 @@ export interface ProxyTestResult {
}
/**
- * 代理连接测试器
+ * Proxy connection tester
*/
export class ProxyConnectionTester {
- private static readonly DEFAULT_TIMEOUT = 10_000; // 10秒超时
+ private static readonly DEFAULT_TIMEOUT = 10_000; // 10 seconds timeout
private static readonly DEFAULT_TEST_URL = 'https://www.google.com';
/**
- * 测试代理连接
+ * Test proxy connection
*/
static async testConnection(
url: string = this.DEFAULT_TEST_URL,
@@ -77,13 +77,13 @@ export class ProxyConnectionTester {
}
/**
- * 测试指定代理配置的连接
+ * Test connection with specified proxy configuration
*/
static async testProxyConfig(
config: NetworkProxySettings,
testUrl: string = this.DEFAULT_TEST_URL,
): Promise<ProxyTestResult> {
- // 验证配置
+ // Validate configuration
const validation = ProxyConfigValidator.validate(config);
if (!validation.isValid) {
return {
@@ -92,12 +92,12 @@ export class ProxyConnectionTester {
};
}
- // 如果未启用代理,直接测试
+ // If proxy is not enabled, test directly
if (!config.enableProxy) {
return this.testConnection(testUrl);
}
- // 创建临时代理 agent 进行测试
+ // Create temporary proxy agent for testing
try {
const proxyUrl = ProxyUrlBuilder.build(config);
logger.debug(`Testing proxy with URL: ${proxyUrl}`);
@@ -108,7 +108,7 @@ export class ProxyConnectionTester {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), this.DEFAULT_TIMEOUT);
- // 临时设置代理进行测试
+ // Temporarily set proxy for testing
const originalDispatcher = getGlobalDispatcher();
setGlobalDispatcher(agent);
@@ -138,9 +138,9 @@ export class ProxyConnectionTester {
clearTimeout(timeoutId);
throw fetchError;
} finally {
- // 恢复原来的 dispatcher
+ // Restore original dispatcher
setGlobalDispatcher(originalDispatcher);
- // 清理临时创建的代理 agent
+ // Clean up temporary proxy agent
if (agent && typeof agent.destroy === 'function') {
try {
await agent.destroy();
diff --git a/apps/desktop/src/main/modules/networkProxy/urlBuilder.ts b/apps/desktop/src/main/modules/networkProxy/urlBuilder.ts
index d592f91b054..5af1cc2c5de 100644
--- a/apps/desktop/src/main/modules/networkProxy/urlBuilder.ts
+++ b/apps/desktop/src/main/modules/networkProxy/urlBuilder.ts
@@ -1,11 +1,11 @@
import { NetworkProxySettings } from '@lobechat/electron-client-ipc';
/**
- * 代理 URL 构建器
+ * Proxy URL builder
*/
export const ProxyUrlBuilder = {
/**
- * 构建代理 URL
+ * Build proxy URL
*/
build(config: NetworkProxySettings): string {
const { proxyType, proxyServer, proxyPort, proxyRequireAuth, proxyUsername, proxyPassword } =
@@ -13,7 +13,7 @@ export const ProxyUrlBuilder = {
let proxyUrl = `${proxyType}://${proxyServer}:${proxyPort}`;
- // 添加认证信息
+ // Add authentication information
if (proxyRequireAuth && proxyUsername && proxyPassword) {
const encodedUsername = encodeURIComponent(proxyUsername);
const encodedPassword = encodeURIComponent(proxyPassword);
diff --git a/apps/desktop/src/main/modules/networkProxy/validator.ts b/apps/desktop/src/main/modules/networkProxy/validator.ts
index 8234b432356..46b02fb248e 100644
--- a/apps/desktop/src/main/modules/networkProxy/validator.ts
+++ b/apps/desktop/src/main/modules/networkProxy/validator.ts
@@ -1,7 +1,7 @@
import { NetworkProxySettings } from '@lobechat/electron-client-ipc';
/**
- * 代理配置验证结果
+ * Proxy configuration validation result
*/
export interface ProxyValidationResult {
errors: string[];
@@ -9,38 +9,38 @@ export interface ProxyValidationResult {
}
/**
- * 代理配置验证器
+ * Proxy configuration validator
*/
export class ProxyConfigValidator {
private static readonly SUPPORTED_TYPES = ['http', 'https', 'socks5'] as const;
private static readonly DEFAULT_BYPASS = 'localhost,127.0.0.1,::1';
/**
- * 验证代理配置
+ * Validate proxy configuration
*/
static validate(config: NetworkProxySettings): ProxyValidationResult {
const errors: string[] = [];
- // 如果未启用代理,跳过验证
+ // If proxy is not enabled, skip validation
if (!config.enableProxy) {
return { errors: [], isValid: true };
}
- // 验证代理类型
+ // Validate proxy type
if (!this.SUPPORTED_TYPES.includes(config.proxyType as any)) {
errors.push(
`Unsupported proxy type: ${config.proxyType}. Supported types: ${this.SUPPORTED_TYPES.join(', ')}`,
);
}
- // 验证代理服务器
+ // Validate proxy server
if (!config.proxyServer?.trim()) {
errors.push('Proxy server is required when proxy is enabled');
} else if (!this.isValidHost(config.proxyServer)) {
errors.push('Invalid proxy server format');
}
- // 验证代理端口
+ // Validate proxy port
if (!config.proxyPort?.trim()) {
errors.push('Proxy port is required when proxy is enabled');
} else {
@@ -50,7 +50,7 @@ export class ProxyConfigValidator {
}
}
- // 验证认证信息
+ // Validate authentication information
if (config.proxyRequireAuth) {
if (!config.proxyUsername?.trim()) {
errors.push('Proxy username is required when authentication is enabled');
@@ -67,10 +67,10 @@ export class ProxyConfigValidator {
}
/**
- * 验证主机名格式
+ * Validate host format
*/
private static isValidHost(host: string): boolean {
- // 简单的主机名验证(IP 地址或域名)
+ // Simple host validation (IP address or domain name)
const ipRegex = /^(\d{1,3}\.){3}\d{1,3}$/;
const domainRegex =
/^[\dA-Za-z]([\dA-Za-z-]*[\dA-Za-z])?(\.[\dA-Za-z]([\dA-Za-z-]*[\dA-Za-z])?)*$/;