diff --git a/src-tauri/locales/en.json b/src-tauri/locales/en.json index 2424a99..c59e6f6 100644 --- a/src-tauri/locales/en.json +++ b/src-tauri/locales/en.json @@ -769,6 +769,7 @@ "no_proxy": "No Proxy", "proxy_host": "Proxy Host", "proxy_host_placeholder": "e.g. 127.0.0.1", + "proxy_host_invalid": "Invalid hostname format. Please enter a valid IP address or domain name", "proxy_port": "Proxy Port", "proxy_port_placeholder": "e.g. 7890", "proxy_username": "Proxy Username", diff --git a/src-tauri/locales/zh-cn.json b/src-tauri/locales/zh-cn.json index d74e67a..a939579 100644 --- a/src-tauri/locales/zh-cn.json +++ b/src-tauri/locales/zh-cn.json @@ -782,6 +782,7 @@ "no_proxy": "不使用代理", "proxy_host": "代理主机", "proxy_host_placeholder": "例如:127.0.0.1", + "proxy_host_invalid": "主机名格式无效,请输入有效的IP地址或域名", "proxy_port": "代理端口", "proxy_port_placeholder": "例如:7890", "proxy_username": "代理用户名", diff --git a/src-tauri/locales/zh-hant.json b/src-tauri/locales/zh-hant.json index 55915e6..8d22fec 100644 --- a/src-tauri/locales/zh-hant.json +++ b/src-tauri/locales/zh-hant.json @@ -736,6 +736,7 @@ "no_proxy": "不使用代理", "proxy_host": "代理主機", "proxy_host_placeholder": "例如:127.0.0.1", + "proxy_host_invalid": "主機名格式無效,請輸入有效的IP地址或域名", "proxy_port": "代理端口", "proxy_port_placeholder": "例如:7890", "proxy_username": "代理用戶名", diff --git a/src/controller/storage/mount/mount.ts b/src/controller/storage/mount/mount.ts index 76928f6..664caf4 100644 --- a/src/controller/storage/mount/mount.ts +++ b/src/controller/storage/mount/mount.ts @@ -56,10 +56,11 @@ function getMountStorage(mountPath: string): MountListItem | undefined { } /** - * 检查是否已挂载 + * 检查挂载配置是否存在(同步版本,仅检查配置,不检查实际挂载状态) + * 注意:此函数检查的是配置是否存在,而非实际的rclone挂载状态 + * 如需检查实际挂载状态,请使用 mountRepository.isMounted()(异步版本) */ function isMounted(mountPath: string): boolean { - // 同步版本,用于 UI 判断 const mountList = mountRepository.getMountConfig(mountPath) return mountList !== undefined } diff --git a/src/page/setting/components/AdvancedSettings.tsx b/src/page/setting/components/AdvancedSettings.tsx index 0c7f7ce..e8ddf96 100644 --- a/src/page/setting/components/AdvancedSettings.tsx +++ b/src/page/setting/components/AdvancedSettings.tsx @@ -11,6 +11,16 @@ import { clearAllCache } from '../../../utils/tempCleanup' const FormItem = Form.Item +/** + * 验证主机名格式(允许IP地址、域名、localhost) + */ +function isValidHostname(hostname: string): boolean { + if (!hostname) return false + // 允许: IP地址、域名、localhost + const hostnameRegex = /^[a-zA-Z0-9]([a-zA-Z0-9\-\.]*[a-zA-Z0-9])?$/ + return hostnameRegex.test(hostname) +} + export function AdvancedSettings(): JSX.Element { const { t } = useTranslation() const { increment: incrementSettings } = useSettingsStore() @@ -59,6 +69,12 @@ export function AdvancedSettings(): JSX.Element { incrementSettings() } }} + onBlur={e => { + const value = e.target.value + if (value && !isValidHostname(value)) { + Message.warning(t('proxy_host_invalid')) + } + }} /> diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index c852e11..33b716a 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -164,6 +164,10 @@ class ConfigService { if (this.config.framework?.openlist?.password) { this.config.framework.openlist.password = decodePassword(this.config.framework.openlist.password) } + // 解码代理密码 + if (this.config.settings?.proxy?.password) { + this.config.settings.proxy.password = decodePassword(this.config.settings.proxy.password) + } logger.info('Config loaded from disk', 'ConfigService') } catch (error) { @@ -185,6 +189,10 @@ class ConfigService { if (configToSave.framework?.openlist?.password) { configToSave.framework.openlist.password = encodePassword(configToSave.framework.openlist.password) } + // 编码代理密码 + if (configToSave.settings?.proxy?.password) { + configToSave.settings.proxy.password = encodePassword(configToSave.settings.proxy.password) + } await invoke('update_config', { data: configToSave, diff --git a/src/utils/rclone/process.ts b/src/utils/rclone/process.ts index 5e7738c..3940bd0 100644 --- a/src/utils/rclone/process.ts +++ b/src/utils/rclone/process.ts @@ -11,13 +11,14 @@ import { LOCALHOST_URLS } from '../../constants' import { netmountLogDir, rcloneConfigFile, rcloneLogFile } from '../netmountPaths' import { restartSidecar, startSidecarAndWait, stopSidecarGracefully } from '../sidecarService' import { parseExtraCliArgs } from '../cliArgs' +import type { NMConfig } from '../../type/config' /** * 构建代理URL * 根据代理配置生成 rclone --http-proxy 参数值 * 支持 HTTP 和 SOCKS5 代理,格式:protocol://[user:pass@]host:port */ -function buildProxyUrl(proxy: { type: string; host?: string; port?: number; username?: string; password?: string }): string | undefined { +function buildProxyUrl(proxy: NonNullable): string | undefined { if (proxy.type === 'no_proxy' || !proxy.host || !proxy.port) { return undefined }