diff --git a/apps/desktop/src-tauri/src/infrastructure/comfyui_service.rs b/apps/desktop/src-tauri/src/infrastructure/comfyui_service.rs index 0ce6c22..fea6566 100644 --- a/apps/desktop/src-tauri/src/infrastructure/comfyui_service.rs +++ b/apps/desktop/src-tauri/src/infrastructure/comfyui_service.rs @@ -123,47 +123,43 @@ impl ComfyuiInfrastructureService { let response_url = response.url().to_string(); info!("Response URL: {}", response_url); - // 尝试解析响应,如果失败则返回基本成功响应 - let initial_result: Value = response.json().await - .unwrap_or_else(|_| serde_json::json!({})); - info!("Workflow '{}' execution started", request.base_name); - // 如果响应URL不同于请求URL,说明需要访问新的URL获取结果 - if response_url != url { - info!("Fetching final result from: {}", response_url); + // 总是尝试用 GET 请求获取最终结果 + info!("Using GET request to fetch final result from: {}", response_url); - // 访问响应URL获取最终结果 - match self.client.get(&response_url).send().await { - Ok(final_response) => { - if final_response.status().is_success() { - match final_response.json::().await { - Ok(final_result) => { - info!("Successfully retrieved final result"); - let execute_response = ExecuteWorkflowResponse { - task_id: initial_result.get("task_id").and_then(|v| v.as_str()).map(String::from), - status: Some("completed".to_string()), - message: Some("Workflow execution completed successfully".to_string()), - result: Some(final_result), - error: None, - }; - return Ok(execute_response); - } - Err(e) => { - warn!("Failed to parse final result JSON: {}", e); - } + match self.client.get(&response_url).send().await { + Ok(final_response) => { + if final_response.status().is_success() { + match final_response.json::().await { + Ok(final_result) => { + info!("Successfully retrieved final result via GET"); + let execute_response = ExecuteWorkflowResponse { + task_id: None, // GET 请求通常不返回 task_id + status: Some("completed".to_string()), + message: Some("Workflow execution completed successfully".to_string()), + result: Some(final_result), + error: None, + }; + return Ok(execute_response); + } + Err(e) => { + warn!("Failed to parse final result JSON: {}", e); } - } else { - warn!("Failed to fetch final result: HTTP {}", final_response.status()); } + } else { + warn!("Failed to fetch final result: HTTP {}", final_response.status()); } - Err(e) => { - warn!("Failed to request final result: {}", e); - } + } + Err(e) => { + warn!("Failed to request final result: {}", e); } } - // 如果无法获取最终结果,返回初始响应 + // 如果无法获取最终结果,解析初始响应 + let initial_result: Value = response.json().await + .unwrap_or_else(|_| serde_json::json!({})); + let execute_response = ExecuteWorkflowResponse { task_id: initial_result.get("task_id").and_then(|v| v.as_str()).map(String::from), status: initial_result.get("status").and_then(|v| v.as_str()).map(String::from),