mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: implement CoreConfigValidator for configuration validation and enhance logging types (#5112)
This commit is contained in:
@@ -4,7 +4,7 @@ use super::CmdResult;
|
||||
use crate::{
|
||||
cmd::StringifyErr,
|
||||
config::Config,
|
||||
core::{CoreManager, handle},
|
||||
core::{CoreManager, handle, validate::CoreConfigValidator},
|
||||
};
|
||||
use crate::{config::*, feat, logging, utils::logging::Type, wrap_err};
|
||||
use compact_str::CompactString;
|
||||
@@ -257,7 +257,7 @@ pub async fn get_dns_config_content() -> CmdResult<String> {
|
||||
/// 验证DNS配置文件
|
||||
#[tauri::command]
|
||||
pub async fn validate_dns_config() -> CmdResult<(bool, String)> {
|
||||
use crate::{core::CoreManager, utils::dirs};
|
||||
use crate::utils::dirs;
|
||||
|
||||
let app_dir = dirs::app_home_dir().stringify_err()?;
|
||||
let dns_path = app_dir.join("dns_config.yaml");
|
||||
@@ -267,8 +267,7 @@ pub async fn validate_dns_config() -> CmdResult<(bool, String)> {
|
||||
return Ok((false, "DNS config file not found".into()));
|
||||
}
|
||||
|
||||
CoreManager::global()
|
||||
.validate_config_file(dns_path_str, None)
|
||||
CoreConfigValidator::validate_config_file(dns_path_str, None)
|
||||
.await
|
||||
.stringify_err()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::CmdResult;
|
||||
use crate::{
|
||||
config::*,
|
||||
core::*,
|
||||
core::{validate::CoreConfigValidator, *},
|
||||
logging,
|
||||
utils::{dirs, logging::Type},
|
||||
wrap_err,
|
||||
@@ -48,10 +48,7 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
Type::Config,
|
||||
"[cmd配置save] 检测到merge文件,只进行语法验证"
|
||||
);
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path_str, Some(true))
|
||||
.await
|
||||
{
|
||||
match CoreConfigValidator::validate_config_file(&file_path_str, Some(true)).await {
|
||||
Ok((true, _)) => {
|
||||
logging!(info, Type::Config, "[cmd配置save] merge文件语法验证通过");
|
||||
// 成功后尝试更新整体配置
|
||||
@@ -95,10 +92,7 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
}
|
||||
|
||||
// 非merge文件使用完整验证流程
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path_str, None)
|
||||
.await
|
||||
{
|
||||
match CoreConfigValidator::validate_config_file(&file_path_str, None).await {
|
||||
Ok((true, _)) => {
|
||||
logging!(info, Type::Config, "[cmd配置save] 验证成功");
|
||||
Ok(())
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use super::CmdResult;
|
||||
use crate::{core::*, logging, utils::logging::Type};
|
||||
use crate::{
|
||||
core::{validate::CoreConfigValidator, *},
|
||||
logging,
|
||||
utils::logging::Type,
|
||||
};
|
||||
|
||||
/// 发送脚本验证通知消息
|
||||
#[tauri::command]
|
||||
@@ -38,10 +42,7 @@ pub fn handle_script_validation_notice(result: &(bool, String), file_type: &str)
|
||||
pub async fn validate_script_file(file_path: String) -> CmdResult<bool> {
|
||||
logging!(info, Type::Config, "验证脚本文件: {}", file_path);
|
||||
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path, None)
|
||||
.await
|
||||
{
|
||||
match CoreConfigValidator::validate_config_file(&file_path, None).await {
|
||||
Ok(result) => {
|
||||
handle_script_validation_notice(&result, "脚本文件");
|
||||
Ok(result.0) // 返回验证结果布尔值
|
||||
|
||||
Reference in New Issue
Block a user