适配 UI 分离图片编辑 multipart 接口
Project CI / Frontend tests (pull_request) Successful in 4m57s
Project CI / Repository checks (pull_request) Failing after 10s
Project CI / Backend tests (pull_request) Failing after 11s
Project CI / Native shell tests (pull_request) Failing after 5m40s

将标记图 data URL 解码为 PNG 文件部件。

按 Raw GPT Image 2 新合同发送 prompt、尺寸和输出参数。

保留响应 data[].b64_json 解析与 separation 流程不变。
This commit is contained in:
2026-09-09 13:17:36 +08:00
parent 418d5732de
commit 11d4d3d930
@@ -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