增加主站抠图参数归一化

缺省模式兼容为complex并校验颜色格式

将auto颜色原样保留给BgFilter
This commit is contained in:
2026-09-16 20:26:46 +08:00
parent 5aecadf700
commit 483f636570
@@ -6292,6 +6292,7 @@ pub(crate) async fn enqueue_editor_background_removal_for_owner(
mut payload: EditorBackgroundRemovalRequest,
external_idempotency_key: Option<&str>,
) -> Result<ExternalGenerationJobRecord, AppError> {
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>,