diff --git a/src-tauri/src/commands/relay_stations.rs b/src-tauri/src/commands/relay_stations.rs index 675fbb1..48f0d47 100644 --- a/src-tauri/src/commands/relay_stations.rs +++ b/src-tauri/src/commands/relay_stations.rs @@ -586,12 +586,16 @@ fn validate_relay_station_request(name: &str, api_url: &str, system_token: &str) } // 验证 URL 格式 - if let Err(_) = url::Url::parse(api_url) { - return Err(i18n::t("relay_station.invalid_url")); - } - - // 验证是否为 HTTPS - if !api_url.starts_with("https://") { + let parsed_url = url::Url::parse(api_url) + .map_err(|_| i18n::t("relay_station.invalid_url"))?; + + // 允许本地开发环境使用 HTTP + let is_localhost = parsed_url.host_str() + .map(|host| host == "localhost" || host == "127.0.0.1" || host == "::1" || host.starts_with("192.168.") || host.starts_with("10.")) + .unwrap_or(false); + + // 非本地环境必须使用 HTTPS + if !is_localhost && !api_url.starts_with("https://") { return Err(i18n::t("relay_station.https_required")); } diff --git a/src-tauri/src/i18n.rs b/src-tauri/src/i18n.rs index 1f28e79..fa19272 100644 --- a/src-tauri/src/i18n.rs +++ b/src-tauri/src/i18n.rs @@ -56,6 +56,13 @@ impl SimpleI18n { ("en-US", "relay_adapter.network_error") => "Network connection failed".to_string(), ("en-US", "relay_station.enabled_success") => "Relay station enabled successfully".to_string(), ("en-US", "relay_station.disabled_success") => "Relay station disabled successfully".to_string(), + ("en-US", "relay_station.name_required") => "Station name is required".to_string(), + ("en-US", "relay_station.api_url_required") => "API URL is required".to_string(), + ("en-US", "relay_station.invalid_url") => "Invalid URL format".to_string(), + ("en-US", "relay_station.https_required") => "API URL must use HTTPS protocol for security".to_string(), + ("en-US", "relay_station.token_required") => "API token is required".to_string(), + ("en-US", "relay_station.token_too_short") => "API token is too short (minimum 10 characters)".to_string(), + ("en-US", "relay_station.token_invalid_chars") => "API token contains invalid characters".to_string(), // 中文翻译 ("zh-CN", "error-failed-to-create") => "创建失败".to_string(), @@ -77,6 +84,13 @@ impl SimpleI18n { ("zh-CN", "relay_adapter.network_error") => "网络连接失败".to_string(), ("zh-CN", "relay_station.enabled_success") => "中转站启用成功".to_string(), ("zh-CN", "relay_station.disabled_success") => "中转站禁用成功".to_string(), + ("zh-CN", "relay_station.name_required") => "中转站名称不能为空".to_string(), + ("zh-CN", "relay_station.api_url_required") => "API地址不能为空".to_string(), + ("zh-CN", "relay_station.invalid_url") => "无效的URL格式".to_string(), + ("zh-CN", "relay_station.https_required") => "出于安全考虑,API地址必须使用HTTPS协议".to_string(), + ("zh-CN", "relay_station.token_required") => "API令牌不能为空".to_string(), + ("zh-CN", "relay_station.token_too_short") => "API令牌太短(至少需要10个字符)".to_string(), + ("zh-CN", "relay_station.token_invalid_chars") => "API令牌包含无效字符".to_string(), // 默认情况 _ => key.to_string(),