Load Comfy templates for MoneyPrinter
This commit is contained in:
+34
-10
@@ -3,6 +3,7 @@ use crate::{
|
||||
db::models::{background_task::BackgroundTask, downstream_api_key::DownstreamApiKey},
|
||||
error::{AppError, AppResult},
|
||||
services::workspace::{self, WorkspaceAssetInput},
|
||||
workflow::storage,
|
||||
AppState,
|
||||
};
|
||||
use axum::{
|
||||
@@ -492,19 +493,41 @@ fn comfy_mapping_from_body(body: &Value) -> Value {
|
||||
.unwrap_or_else(default_comfy_mapping)
|
||||
}
|
||||
|
||||
fn workflow_prompt_from_body(body: &Value) -> AppResult<Value> {
|
||||
body.get("comfyPrompt")
|
||||
fn workflow_prompt_from_graph(graph: &Value) -> Value {
|
||||
graph.get("prompt")
|
||||
.cloned()
|
||||
.or_else(|| graph.get("workflow").cloned())
|
||||
.or_else(|| graph.get("comfyPrompt").cloned())
|
||||
.unwrap_or_else(|| graph.clone())
|
||||
}
|
||||
|
||||
async fn workflow_prompt_from_body(
|
||||
state: &AppState,
|
||||
auth: &MoneyPrinterAuth,
|
||||
body: &Value,
|
||||
) -> AppResult<Value> {
|
||||
if let Some(value) = body.get("comfyPrompt")
|
||||
.or_else(|| body.get("comfy_prompt"))
|
||||
.or_else(|| body.get("promptWorkflow"))
|
||||
.or_else(|| body.get("prompt_workflow"))
|
||||
.or_else(|| body.get("workflowPrompt"))
|
||||
.or_else(|| body.get("workflow_prompt"))
|
||||
.cloned()
|
||||
.ok_or_else(|| {
|
||||
AppError::BadRequest(
|
||||
"Comfy API 模式需要传入 comfyPrompt/promptWorkflow 和节点映射".into(),
|
||||
)
|
||||
})
|
||||
.cloned() {
|
||||
return Ok(value);
|
||||
}
|
||||
if let Some(template_id) = string_from(body, &["templateId", "template_id", "workflowId", "workflow_id"]) {
|
||||
let workflow = storage::get_workflow(
|
||||
&state.db,
|
||||
&template_id,
|
||||
auth.user_id,
|
||||
auth.role == "admin",
|
||||
)
|
||||
.await?;
|
||||
return Ok(workflow_prompt_from_graph(&workflow.graph));
|
||||
}
|
||||
Err(AppError::BadRequest(
|
||||
"Comfy API 模式需要选择工作流模板,或传入 comfyPrompt/promptWorkflow 和节点映射".into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn apply_node_input(prompt: &mut Value, node_id: &str, field: &str, value: Value) -> AppResult<()> {
|
||||
@@ -687,6 +710,7 @@ async fn archive_comfy_output(
|
||||
|
||||
async fn submit_comfy_video(
|
||||
state: &AppState,
|
||||
auth: &MoneyPrinterAuth,
|
||||
body: &Value,
|
||||
plan: &Value,
|
||||
) -> AppResult<Value> {
|
||||
@@ -695,7 +719,7 @@ async fn submit_comfy_video(
|
||||
"Comfy API 视频生成需要配置 comfyui.backend = cloud 或 external".into(),
|
||||
));
|
||||
}
|
||||
let mut prompt = workflow_prompt_from_body(body)?;
|
||||
let mut prompt = workflow_prompt_from_body(state, auth, body).await?;
|
||||
let mapping = comfy_mapping_from_body(body);
|
||||
let video_prompt = inject_comfy_video_inputs(&mut prompt, &mapping, body, plan)?;
|
||||
let (prompt_id, response) = submit_comfy_prompt(state, prompt).await?;
|
||||
@@ -908,7 +932,7 @@ async fn create_job(
|
||||
let mut assets = Vec::new();
|
||||
let (submitted, final_video_response, video_url, prompt, model) = if video_backend == "comfy" {
|
||||
update_progress(&state_for_task, &task_id_for_spawn, 3, "正在提交 Comfy API 工作流").await?;
|
||||
let submitted = submit_comfy_video(&state_for_task, &body, &plan).await?;
|
||||
let submitted = submit_comfy_video(&state_for_task, &auth_for_task, &body, &plan).await?;
|
||||
if is_cancelled(&state_for_task, &task_id_for_spawn).await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user