forked from boos/BoosAPI
Default MoneyPrinter videos to BoosAPI route
This commit is contained in:
+23
-31
@@ -585,6 +585,20 @@ fn first_node_by_class(prompt: &serde_json::Map<String, Value>, class_type: &str
|
||||
.map(|(id, _)| id.clone())
|
||||
}
|
||||
|
||||
fn prompt_contains_class_type(prompt: &Value, class_type: &str) -> bool {
|
||||
match prompt {
|
||||
Value::Object(object) => {
|
||||
object
|
||||
.get("class_type")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|value| value == class_type)
|
||||
|| object.values().any(|value| prompt_contains_class_type(value, class_type))
|
||||
}
|
||||
Value::Array(items) => items.iter().any(|value| prompt_contains_class_type(value, class_type)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn infer_comfy_mapping(prompt: &Value) -> Value {
|
||||
let Some(object) = prompt.as_object() else {
|
||||
return default_comfy_mapping();
|
||||
@@ -687,35 +701,6 @@ fn workflow_prompt_from_graph(graph: &Value) -> Value {
|
||||
.unwrap_or_else(|| graph.clone())
|
||||
}
|
||||
|
||||
fn generated_comfy_prompt_from_request(body: &Value) -> Value {
|
||||
let model = string_from(body, &["videoModel", "video_model", "model"])
|
||||
.unwrap_or_else(|| "seedance-1-0-lite-t2v".to_string());
|
||||
let ratio = string_from(body, &["ratio", "aspectRatio", "aspect_ratio"]).unwrap_or_else(|| "9:16".to_string());
|
||||
let resolution = string_from(body, &["resolution", "size"]).unwrap_or_else(|| "1080p".to_string());
|
||||
let duration = body
|
||||
.get("duration")
|
||||
.cloned()
|
||||
.unwrap_or_else(|| json!(30));
|
||||
json!({
|
||||
"1": {
|
||||
"class_type": "BoosAPITextToVideo",
|
||||
"inputs": {
|
||||
"model": model,
|
||||
"prompt": "",
|
||||
"ratio": ratio,
|
||||
"resolution": resolution,
|
||||
"duration": duration
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"class_type": "output.preview_video",
|
||||
"inputs": {
|
||||
"video": ["1", 0]
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn workflow_prompt_from_body(
|
||||
state: &AppState,
|
||||
auth: &MoneyPrinterAuth,
|
||||
@@ -740,7 +725,9 @@ async fn workflow_prompt_from_body(
|
||||
.await?;
|
||||
return Ok(workflow_prompt_from_graph(&workflow.graph));
|
||||
}
|
||||
Ok(generated_comfy_prompt_from_request(body))
|
||||
Err(AppError::BadRequest(
|
||||
"Comfy API 模式需要选择真实 Comfy/Cloud 视频工作流模板,不能使用 BoosAPI 自定义节点".into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn apply_node_input(prompt: &mut Value, node_id: &str, field: &str, value: Value) -> AppResult<()> {
|
||||
@@ -933,6 +920,11 @@ async fn submit_comfy_video(
|
||||
));
|
||||
}
|
||||
let mut prompt = workflow_prompt_from_body(state, auth, body).await?;
|
||||
if prompt_contains_class_type(&prompt, "BoosAPITextToVideo") {
|
||||
return Err(AppError::BadRequest(
|
||||
"当前 Comfy 后端不支持 BoosAPITextToVideo 自定义节点;请改用 BoosAPI /v1/videos 或选择真实 Comfy 视频模板".into(),
|
||||
));
|
||||
}
|
||||
let mut mapping = comfy_mapping_from_body(body);
|
||||
if !mapping_has_node(&mapping, &["prompt", "positive", "text", "promptNode"]) {
|
||||
mapping = infer_comfy_mapping(&prompt);
|
||||
@@ -1138,7 +1130,7 @@ async fn create_job(
|
||||
.await?;
|
||||
|
||||
let video_backend = string_from(&body, &["videoBackend", "video_backend"])
|
||||
.unwrap_or_else(|| "comfy".to_string())
|
||||
.unwrap_or_else(|| "boosapi".to_string())
|
||||
.to_ascii_lowercase();
|
||||
let title = plan
|
||||
.get("title")
|
||||
|
||||
Reference in New Issue
Block a user