From 483f636570911dd5c077ee6e7de26b377fb61cf5 Mon Sep 17 00:00:00 2001 From: Linghong Date: Wed, 16 Sep 2026 20:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BB=E7=AB=99=E6=8A=A0?= =?UTF-8?q?=E5=9B=BE=E5=8F=82=E6=95=B0=E5=BD=92=E4=B8=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 缺省模式兼容为complex并校验颜色格式 将auto颜色原样保留给BgFilter --- .../crates/api-server/src/editor_project.rs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/server-rs/crates/api-server/src/editor_project.rs b/server-rs/crates/api-server/src/editor_project.rs index 481188301..aebeb5965 100644 --- a/server-rs/crates/api-server/src/editor_project.rs +++ b/server-rs/crates/api-server/src/editor_project.rs @@ -6292,6 +6292,7 @@ pub(crate) async fn enqueue_editor_background_removal_for_owner( mut payload: EditorBackgroundRemovalRequest, external_idempotency_key: Option<&str>, ) -> Result { + normalize_editor_background_removal_options(&mut payload)?; let external_request_identity = external_idempotency_key .map(|idempotency_key| { external_api_editor_generation_request_identity( @@ -6403,6 +6404,59 @@ pub(crate) async fn enqueue_editor_background_removal_for_owner( } } +fn normalize_editor_background_removal_options( + payload: &mut EditorBackgroundRemovalRequest, +) -> Result<(), AppError> { + let mode = payload + .background_mode + .take() + .map(|value| value.trim().to_ascii_lowercase()) + .filter(|value| !value.is_empty()) + .unwrap_or_else(|| "complex".to_string()); + if mode != "complex" && mode != "flat" { + return Err( + AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({ + "provider": "editor-background-removal", + "field": "backgroundMode", + "message": "backgroundMode must be complex or flat", + })), + ); + } + let color = payload + .screen_color + .take() + .map(|value| value.trim().to_string()) + .filter(|value| !value.is_empty()); + if mode == "complex" && color.is_some() { + return Err( + AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({ + "provider": "editor-background-removal", + "field": "screenColor", + "message": "screenColor is only supported when backgroundMode is flat", + })), + ); + } + if let Some(color) = color.as_deref() + && color != "auto" + && !(color.len() == 7 + && color.starts_with('#') + && color[1..] + .chars() + .all(|character| character.is_ascii_hexdigit())) + { + return Err( + AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({ + "provider": "editor-background-removal", + "field": "screenColor", + "message": "screenColor must be auto or #RRGGBB", + })), + ); + } + payload.background_mode = Some(mode); + payload.screen_color = color; + Ok(()) +} + fn resolve_editor_background_removal_canvas_target( project_id: Option<&str>, target_layer_id: Option<&str>,