From 11d4d3d930393e53ca61581b4de3a7127bb3b790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 9 Sep 2026 13:17:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=20UI=20=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=BC=96=E8=BE=91=20multipart=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将标记图 data URL 解码为 PNG 文件部件。 按 Raw GPT Image 2 新合同发送 prompt、尺寸和输出参数。 保留响应 data[].b64_json 解析与 separation 流程不变。 --- .../ui_editor/commands/separation/workflow.rs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) 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