diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow.rs index dabc5f1a7..cf03003a7 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow.rs @@ -154,6 +154,15 @@ async fn raw_image_edit( .strip_prefix("data:") .and_then(|v| v.strip_suffix(";base64")) .unwrap_or("image/png"); + if !mime.eq_ignore_ascii_case("image/png") { + return Err("图片分离请求只支持 PNG 标记图".to_string()); + } + let image_bytes = base64::engine::general_purpose::STANDARD + .decode(data.trim()) + .map_err(|error| format!("解码标记图失败:{error}"))?; + if image_bytes.is_empty() { + return Err("标记图不能为空".to_string()); + } let client = crate::http_client::agc_main_site_client_builder() .build() .map_err(|e| format!("创建图片编辑客户端失败:{e}"))?; @@ -161,19 +170,22 @@ async fn raw_image_edit( "{}/api/raw/v1/images/edit", session.api_base_url.trim_end_matches('/') ); - let body = serde_json::json!({ - "image": {"data": data, "mimeType": mime}, - "prompt": prompt, - "width": width, - "height": height, - "output_format": "png", - "background": "transparent" - }); + let image_part = reqwest::multipart::Part::bytes(image_bytes) + .file_name("image.png") + .mime_str("image/png") + .map_err(|error| format!("构造图片编辑文件部件失败:{error}"))?; + let body = reqwest::multipart::Form::new() + .part("image", image_part) + .text("prompt", prompt.to_string()) + .text("width", width.to_string()) + .text("height", height.to_string()) + .text("output_format", "png") + .text("background", "transparent"); let response = crate::http_client::with_agc_main_site_marker( client .post(url) .bearer_auth(&session.access_token) - .json(&body), + .multipart(body), ) .send() .await