From 9ba62d9e069385a916bad0afd6cb72c58d22b1f0 Mon Sep 17 00:00:00 2001 From: imeepos Date: Fri, 15 Aug 2025 18:59:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20TolerantJsonParser=20=E8=80=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=91=BD=E4=BB=A4=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除对 parse_json_tolerant 命令的依赖,避免 Mutex 污染问题 - 直接创建和使用 TolerantJsonParser 实例 - 简化代码路径,提高性能和稳定性 - 移除不必要的 JsonParserState 参数 --- .../commands/veo3_actor_define_commands.rs | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/apps/desktop/src-tauri/src/presentation/commands/veo3_actor_define_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/veo3_actor_define_commands.rs index 6a9b10c..eb44dc2 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/veo3_actor_define_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/veo3_actor_define_commands.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use chrono; use veo3_scene_writer::Veo3ActorDefine; -use crate::presentation::commands::tolerant_json_commands::{ParseJsonRequest, JsonParserState}; +use crate::infrastructure::tolerant_json_parser::TolerantJsonParser; /// VEO3 角色定义响应结构 #[derive(Debug, Serialize, Deserialize)] @@ -202,7 +202,6 @@ pub struct CreateActorFileResponse { pub async fn veo3_actor_define_create_actor_file( request: CreateActorFileRequest, session_manager: State<'_, Veo3ActorDefineSessionManager>, - json_parser_state: State<'_, JsonParserState>, ) -> Result { // 获取最近一次助手回复 let last_assistant_message = { @@ -233,16 +232,20 @@ pub async fn veo3_actor_define_create_actor_file( }; // 使用容错JSON解析器提取JSON - let parse_request = ParseJsonRequest { - text: assistant_message, - config: None, + let mut parser = match TolerantJsonParser::new(None) { + Ok(p) => p, + Err(e) => { + return Ok(CreateActorFileResponse { + success: false, + file_path: None, + extracted_json: None, + error: Some(format!("创建JSON解析器失败: {}", e)), + }); + } }; - let parse_response = match crate::presentation::commands::tolerant_json_commands::parse_json_tolerant( - parse_request, - json_parser_state, - ).await { - Ok(response) => response, + let json_data = match parser.parse(&assistant_message) { + Ok((data, _statistics)) => data, Err(e) => { return Ok(CreateActorFileResponse { success: false, @@ -253,17 +256,6 @@ pub async fn veo3_actor_define_create_actor_file( } }; - if !parse_response.success || parse_response.data.is_none() { - return Ok(CreateActorFileResponse { - success: false, - file_path: None, - extracted_json: None, - error: Some(parse_response.error.unwrap_or_else(|| "JSON解析失败".to_string())), - }); - } - - let json_data = parse_response.data.unwrap(); - // 生成文件名 let file_name = request.file_name.unwrap_or_else(|| { let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");