From d58499b5648aaab759bfd479168d1b4aba9aba4a Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 5 Aug 2025 18:36:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=81=AB=E5=B1=B1?= =?UTF-8?q?=E4=BA=91=20API=20=E5=93=8D=E5=BA=94=E6=A0=BC=E5=BC=8F=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题修复: - 修复响应结构不匹配导致的解析失败 - 更新数据结构以匹配火山云 API 的实际响应格式 - 添加调试日志以便排查 API 响应问题 技术改进: - 重构响应数据结构,支持火山云嵌套格式 (ResponseMetadata + Result) - 更新前端类型定义和数据访问路径 - 添加详细的响应解析错误信息 - 保持向后兼容性 响应格式变更: - 原格式: { code, message, data, ... } - 新格式: { ResponseMetadata: {...}, Result: { code, message, data, ... } } 现在 OmniHuman 主体识别功能应该可以正确解析火山云 API 响应了! --- .../services/volcano_video_service.rs | 38 +++++++++++++++++-- .../pages/tools/OmniHumanDetectionTool.tsx | 20 +++++----- apps/desktop/src/types/videoGeneration.ts | 17 ++++++++- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs b/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs index a6ac4df..8c38470 100644 --- a/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs +++ b/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs @@ -92,9 +92,33 @@ pub struct RealmanAvatarPictureCreateRoleOmniRequest { pub image_url: String, } -/// OmniHuman 主体识别响应 +/// 火山云 API 响应元数据 +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct VolcanoResponseMetadata { + #[serde(rename = "Action")] + pub action: String, + #[serde(rename = "Region")] + pub region: String, + #[serde(rename = "RequestId")] + pub request_id: String, + #[serde(rename = "Service")] + pub service: String, + #[serde(rename = "Version")] + pub version: String, +} + +/// OmniHuman 主体识别响应 (火山云格式) #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RealmanAvatarPictureCreateRoleOmniResponse { + #[serde(rename = "ResponseMetadata")] + pub response_metadata: VolcanoResponseMetadata, + #[serde(rename = "Result")] + pub result: RealmanAvatarPictureCreateRoleOmniResult, +} + +/// OmniHuman 主体识别结果 +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RealmanAvatarPictureCreateRoleOmniResult { pub code: i32, pub message: String, pub data: Option, @@ -561,10 +585,16 @@ impl VolcanoVideoService { return Err(anyhow!("OmniHuman 主体识别 API 调用失败: {} - {}", status, error_text)); } - let api_response: RealmanAvatarPictureCreateRoleOmniResponse = response.json().await?; + // 先获取响应文本进行调试 + let response_text = response.text().await?; + info!("OmniHuman API 原始响应: {}", response_text); - if api_response.code != 10000 { - return Err(anyhow!("OmniHuman 主体识别 API 返回错误: {} - {}", api_response.code, api_response.message)); + // 尝试解析响应 + let api_response: RealmanAvatarPictureCreateRoleOmniResponse = serde_json::from_str(&response_text) + .map_err(|e| anyhow!("解析响应失败: {} - 响应内容: {}", e, response_text))?; + + if api_response.result.code != 10000 { + return Err(anyhow!("OmniHuman 主体识别 API 返回错误: {} - {}", api_response.result.code, api_response.result.message)); } info!("OmniHuman 主体识别任务提交成功: {:?}", api_response); diff --git a/apps/desktop/src/pages/tools/OmniHumanDetectionTool.tsx b/apps/desktop/src/pages/tools/OmniHumanDetectionTool.tsx index e6be351..9c2058c 100644 --- a/apps/desktop/src/pages/tools/OmniHumanDetectionTool.tsx +++ b/apps/desktop/src/pages/tools/OmniHumanDetectionTool.tsx @@ -90,11 +90,11 @@ const OmniHumanDetectionTool: React.FC = () => { setUploadProgress(100); setResult(response); - if (response.code === 10000) { + if (response.Result.code === 10000) { success('主体识别任务提交成功'); } else { - setErrorMessage(`识别失败: ${response.message}`); - error(`识别失败: ${response.message}`); + setErrorMessage(`识别失败: ${response.Result.message}`); + error(`识别失败: ${response.Result.message}`); } } catch (err) { const errMsg = err instanceof Error ? err.message : '未知错误'; @@ -221,17 +221,17 @@ const OmniHumanDetectionTool: React.FC = () => { 识别成功
-

任务ID: {result.data?.task_id}

-

请求ID: {result.request_id}

-

处理时间: {result.time_elapsed}

+

任务ID: {result.Result.data?.task_id}

+

请求ID: {result.Result.request_id}

+

处理时间: {result.Result.time_elapsed}

- {result.data?.image_urls && result.data.image_urls.length > 0 && ( + {result.Result.data?.image_urls && result.Result.data.image_urls.length > 0 && (

处理后的图片

- {result.data.image_urls.map((url, index) => ( + {result.Result.data.image_urls.map((url, index) => (
{
)} - {result.data?.resp_data && ( + {result.Result.data?.resp_data && (

算法返回数据

- {result.data.resp_data} + {result.Result.data.resp_data}
)} diff --git a/apps/desktop/src/types/videoGeneration.ts b/apps/desktop/src/types/videoGeneration.ts index 1cd3a56..2c69b60 100644 --- a/apps/desktop/src/types/videoGeneration.ts +++ b/apps/desktop/src/types/videoGeneration.ts @@ -412,7 +412,15 @@ export interface RealmanAvatarPictureCreateRoleOmniData { algorithm_base_resp?: any; } -export interface RealmanAvatarPictureCreateRoleOmniResponse { +export interface VolcanoResponseMetadata { + Action: string; + Region: string; + RequestId: string; + Service: string; + Version: string; +} + +export interface RealmanAvatarPictureCreateRoleOmniResult { /** 业务侧错误码 */ code: number; /** 描述信息 */ @@ -426,3 +434,10 @@ export interface RealmanAvatarPictureCreateRoleOmniResponse { /** 内部服务耗时 */ time_elapsed: string; } + +export interface RealmanAvatarPictureCreateRoleOmniResponse { + /** 火山云响应元数据 */ + ResponseMetadata: VolcanoResponseMetadata; + /** 实际结果数据 */ + Result: RealmanAvatarPictureCreateRoleOmniResult; +}