mirror of
https://github.com/VirtualHotBar/NetMount.git
synced 2026-06-08 23:52:34 +08:00
fix: 代码审查修复 - 代理密码编码、类型一致性、主机名验证
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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": "代理用户名",
|
||||
|
||||
@@ -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": "代理用戶名",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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'))
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label={t('proxy_port')}>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<NMConfig['settings']['proxy']>): string | undefined {
|
||||
if (proxy.type === 'no_proxy' || !proxy.host || !proxy.port) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user