chore: remove local deployment and template artifacts

This commit is contained in:
boos
2026-07-14 03:34:59 +08:00
parent d68da02d9b
commit bdd26a5e43
4 changed files with 106 additions and 268 deletions
+25 -7
View File
@@ -23,8 +23,8 @@ use std::time::Duration;
const TEMPLATE_GALLERY_PAGE_URL: &str =
"https://weiyyin.github.io/linux-do-gpt-image/prompt_gallery.html";
const LINUX_DO_TEMPLATE_JSON: &str =
include_str!("../../assets/picture-agent/linux_do_2036927_prompts_images.with_tags.json");
const TEMPLATE_DATA_URL: &str =
"https://weiyyin.github.io/linux-do-gpt-image/linux_do_2036927_prompts_images.with_tags.json";
const TASK_TYPE_PICTURE_GENERATION: &str = "picture-agent-generation";
const PICTURE_GENERATION_TIMEOUT_SECS: u64 = 300;
const PICTURE_GENERATION_RETRY_SECS: u64 = 180;
@@ -435,10 +435,10 @@ async fn templates_handler(
) -> AppResult<Json<Value>> {
let _auth = resolve_picture_agent_auth(&headers, &state).await?;
let limit = query.limit.unwrap_or(144).clamp(1, 240);
let (templates, local_status) = match parse_gallery_templates(LINUX_DO_TEMPLATE_JSON, limit) {
Ok(templates) => (templates, json!({ "ok": true, "source": "local-json" })),
let (templates, remote_status) = match fetch_gallery_templates(&state.http, limit).await {
Ok(templates) => (templates, json!({ "ok": true, "source": "remote-json" })),
Err(err) => {
tracing::warn!(%err, "Picture Agent local Linux Do template gallery unavailable");
tracing::warn!(%err, "Picture Agent remote Linux Do template gallery unavailable");
(Vec::new(), json!({ "ok": false, "message": err }))
}
};
@@ -446,17 +446,35 @@ async fn templates_handler(
Ok(Json(json!({
"success": true,
"sourceUrl": TEMPLATE_GALLERY_PAGE_URL,
"source": local_status,
"source": remote_status,
"templates": templates,
})))
}
async fn fetch_gallery_templates(
client: &reqwest::Client,
limit: usize,
) -> Result<Vec<Value>, String> {
let raw = client
.get(TEMPLATE_DATA_URL)
.send()
.await
.map_err(|err| format!("failed to fetch remote Linux Do templates: {err}"))?
.error_for_status()
.map_err(|err| format!("remote Linux Do templates returned an error: {err}"))?
.text()
.await
.map_err(|err| format!("failed to read remote Linux Do templates: {err}"))?;
parse_gallery_templates(&raw, limit)
}
fn parse_gallery_templates(raw: &str, limit: usize) -> Result<Vec<Value>, String> {
if limit == 0 {
return Ok(Vec::new());
}
let items = serde_json::from_str::<Vec<GalleryItem>>(raw)
.map_err(|err| format!("failed to parse local Linux Do templates: {err}"))?;
.map_err(|err| format!("failed to parse remote Linux Do templates: {err}"))?;
Ok(items
.into_iter()