From e8806870043ca2e86eb785005f0e10c36435cfbc Mon Sep 17 00:00:00 2001 From: imeepos Date: Wed, 30 Jul 2025 21:51:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DComfyUI=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E6=8F=90=E7=A4=BA=E8=AF=8D=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E5=92=8C=E9=94=99=E8=AF=AF=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化节点识别逻辑,正确识别模特描述节点为提示词类型 - 根据节点class_type智能选择替换字段(String类型用value,其他用text) - 修复ComfyUI错误判断逻辑,空node_errors对象不再误判为失败 - 确保ComfyUI任务成功创建时不会被错误标记为失败状态 - 提升工作流执行成功率和用户体验 --- .../src/business/services/comfyui_service.rs | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src-tauri/src/business/services/comfyui_service.rs b/apps/desktop/src-tauri/src/business/services/comfyui_service.rs index 4dc46b5..f0d1313 100644 --- a/apps/desktop/src-tauri/src/business/services/comfyui_service.rs +++ b/apps/desktop/src-tauri/src/business/services/comfyui_service.rs @@ -308,11 +308,11 @@ impl ComfyUIService { if let Some(Value::String(title)) = meta.get("title") { if title.contains("BOWONG-INPUT-") { should_replace = true; - if title.contains("模特") || title.contains("MODEL") || title.contains("AVATAR") { + if title.contains("模特") && !title.contains("描述") { replacement_type = "model"; } else if title.contains("穿搭") || title.contains("商品") || title.contains("PRODUCT") || title.contains("CLOTH") { replacement_type = "product"; - } else if title.contains("提示") || title.contains("PROMPT") || title.contains("TEXT") { + } else if title.contains("提示") || title.contains("PROMPT") || title.contains("TEXT") || title.contains("描述") { replacement_type = "prompt"; } else if title.contains("负面") || title.contains("NEGATIVE") { replacement_type = "negative"; @@ -364,17 +364,48 @@ impl ComfyUIService { }); } "prompt" => { + // 根据节点类型决定使用哪个字段 + let field_name = if let Value::Object(node_obj) = node_value { + if let Some(Value::String(class_type)) = node_obj.get("class_type") { + if class_type == "String" { + "value" + } else { + "text" + } + } else { + "text" + } + } else { + "text" + }; + replacements.push(WorkflowNodeReplacement { node_id: node_id.clone(), - input_field: "text".to_string(), + input_field: field_name.to_string(), value: Value::String(prompt.to_string()), }); } "negative" => { let neg_prompt = negative_prompt.unwrap_or(""); + + // 根据节点类型决定使用哪个字段 + let field_name = if let Value::Object(node_obj) = node_value { + if let Some(Value::String(class_type)) = node_obj.get("class_type") { + if class_type == "String" { + "value" + } else { + "text" + } + } else { + "text" + } + } else { + "text" + }; + replacements.push(WorkflowNodeReplacement { node_id: node_id.clone(), - input_field: "text".to_string(), + input_field: field_name.to_string(), value: Value::String(neg_prompt.to_string()), }); } @@ -438,7 +469,16 @@ impl ComfyUIService { .map_err(|e| ComfyUIError::NetworkError(format!("解析响应失败: {}", e)))?; if let Some(errors) = prompt_response.node_errors { - return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors))); + // 检查是否真的有错误(不是空对象) + if let Value::Object(error_map) = &errors { + if !error_map.is_empty() { + return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors))); + } + } else if errors != Value::Object(serde_json::Map::new()) { + return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors))); + } + // 如果是空对象 {} 则不认为是错误 + info!("收到空的节点错误对象,继续执行"); } info!("工作流提交成功,提示 ID: {}", prompt_response.prompt_id);