forked from boos/BoosAPI
Handle Comfy Cloud video job status
This commit is contained in:
@@ -963,16 +963,44 @@ async fn comfy_json(
|
||||
}
|
||||
|
||||
async fn comfy_history(state: &AppState, prompt_id: &str) -> AppResult<Value> {
|
||||
let history = comfy_json(state, reqwest::Method::GET, &format!("/history/{prompt_id}"), None).await?;
|
||||
let path = if state.config.comfyui.uses_cloud_backend() {
|
||||
format!("/jobs/{prompt_id}")
|
||||
} else {
|
||||
format!("/history/{prompt_id}")
|
||||
};
|
||||
let history = comfy_json(state, reqwest::Method::GET, &path, None).await?;
|
||||
let failed = comfy_failure_message(&history);
|
||||
Ok(json!({
|
||||
"id": prompt_id,
|
||||
"object": "video.generation.task",
|
||||
"backend": "comfy",
|
||||
"status": if comfy_output_objects(&history) { "succeeded" } else { "running" },
|
||||
"status": if failed.is_some() {
|
||||
"failed"
|
||||
} else if comfy_output_objects(&history) {
|
||||
"succeeded"
|
||||
} else {
|
||||
"running"
|
||||
},
|
||||
"error": failed,
|
||||
"history": history,
|
||||
}))
|
||||
}
|
||||
|
||||
fn comfy_failure_message(value: &Value) -> Option<String> {
|
||||
let status = scalar_string(value.get("status").or_else(|| value.get("state")))
|
||||
.unwrap_or_default()
|
||||
.to_ascii_lowercase();
|
||||
if matches!(status.as_str(), "failed" | "error" | "cancelled" | "canceled") {
|
||||
return Some(
|
||||
scalar_string(value.pointer("/execution_error/exception_message"))
|
||||
.or_else(|| scalar_string(value.get("error")))
|
||||
.or_else(|| scalar_string(value.get("message")))
|
||||
.unwrap_or_else(|| format!("Comfy job {status}")),
|
||||
);
|
||||
}
|
||||
scalar_string(value.pointer("/execution_error/exception_message"))
|
||||
}
|
||||
|
||||
fn comfy_output_objects(value: &Value) -> bool {
|
||||
match value {
|
||||
Value::Object(object) => {
|
||||
|
||||
Reference in New Issue
Block a user