Add GET /enhance/prompts: recent distinct Enhance prompts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6d04589d1
commit
cdc339021b
7 files changed
+243
-3
No files matched your search
@@ -3,6 +3,7 @@
|
||||
//!
|
||||
//! - `GET /enhance/templates`
|
||||
//! - `POST /enhance`
|
||||
//! - `GET /enhance/prompts?templates=&limit=`
|
||||
//! - `GET /enhance/jobs?path=`
|
||||
//! - `GET /enhance/jobs/{id}`
|
||||
//! - `GET /enhance/jobs/{id}/preview/{n}`
|
||||
@@ -363,6 +364,57 @@ pub async fn list_jobs(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PromptsQuery {
|
||||
/// Comma-separated template names; omitted = all templates.
|
||||
pub templates: Option<String>,
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct PromptView {
|
||||
prompt: String,
|
||||
template: String,
|
||||
last_used: i64,
|
||||
uses: i64,
|
||||
}
|
||||
|
||||
/// Prompts used before, newest first, so the app can offer them again for a
|
||||
/// series of similar photos. DB only: not library-scoped, and answered even
|
||||
/// when ComfyUI is down or Enhance is off (then simply from old rows).
|
||||
#[get("/enhance/prompts")]
|
||||
pub async fn recent_prompts(
|
||||
_: Claims,
|
||||
q: web::Query<PromptsQuery>,
|
||||
svc: web::Data<EnhanceService>,
|
||||
) -> impl Responder {
|
||||
let names: Option<Vec<String>> = q.templates.as_deref().map(|t| {
|
||||
t.split(',')
|
||||
.map(str::trim)
|
||||
.filter(|n| !n.is_empty())
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
});
|
||||
// `templates=` with nothing in it means "no filter", like omitting it.
|
||||
let names = names.filter(|n| !n.is_empty());
|
||||
let limit = q.limit.unwrap_or(10).clamp(1, 50);
|
||||
match svc.recent_prompts(names.as_deref(), limit) {
|
||||
Ok(rows) => {
|
||||
let prompts: Vec<PromptView> = rows
|
||||
.into_iter()
|
||||
.map(|r| PromptView {
|
||||
prompt: r.prompt,
|
||||
template: r.template,
|
||||
last_used: r.last_used,
|
||||
uses: r.uses,
|
||||
})
|
||||
.collect();
|
||||
HttpResponse::Ok().json(json!({ "prompts": prompts }))
|
||||
}
|
||||
Err(e) => error_response(&e),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/enhance/jobs/{id}/preview/{n}")]
|
||||
pub async fn preview(
|
||||
_: Claims,
|
||||
|
||||
Reference in new issue
Block a user