Proxy external template requests

This commit is contained in:
boos
2026-06-01 11:21:56 +08:00
parent 04792bd3f7
commit 7b34153235
9 changed files with 58 additions and 12 deletions
+1
View File
@@ -409,6 +409,7 @@ mod tests {
first_byte_timeout_secs: 30,
max_retries: 3,
proxy_log_retention_days: 7,
template_proxy_url: None,
},
comfyui: Default::default(),
},
+1
View File
@@ -341,6 +341,7 @@ mod tests {
first_byte_timeout_secs: 30,
max_retries: 3,
proxy_log_retention_days: 7,
template_proxy_url: None,
},
comfyui: Default::default(),
},
+1
View File
@@ -1235,6 +1235,7 @@ mod tests {
first_byte_timeout_secs: 30,
max_retries: 3,
proxy_log_retention_days: 7,
template_proxy_url: None,
},
comfyui: Default::default(),
},
+10 -11
View File
@@ -345,8 +345,11 @@ async fn templates_handler(
let _auth = resolve_picture_agent_auth(&headers, &state).await?;
let limit = query.limit.unwrap_or(144).clamp(1, 240);
let mut templates = builtin_picture_templates(limit);
let remote_status = match fetch_remote_gallery_templates(limit.saturating_sub(templates.len()))
.await
let remote_status = match fetch_remote_gallery_templates(
&state.config,
limit.saturating_sub(templates.len()),
)
.await
{
Ok(mut remote_templates) => {
templates.append(&mut remote_templates);
@@ -368,11 +371,14 @@ async fn templates_handler(
})))
}
async fn fetch_remote_gallery_templates(limit: usize) -> Result<Vec<Value>, String> {
async fn fetch_remote_gallery_templates(
config: &crate::config::AppConfig,
limit: usize,
) -> Result<Vec<Value>, String> {
if limit == 0 {
return Ok(Vec::new());
}
let items = template_client()
let items = crate::template_http::client(config, TEMPLATE_GALLERY_TIMEOUT_SECS)
.get(TEMPLATE_GALLERY_URL)
.send()
.await
@@ -499,13 +505,6 @@ fn builtin_picture_templates(limit: usize) -> Vec<Value> {
.collect()
}
fn template_client() -> Client {
Client::builder()
.timeout(Duration::from_secs(TEMPLATE_GALLERY_TIMEOUT_SECS))
.build()
.unwrap_or_else(|_| Client::new())
}
fn picture_generation_client() -> Client {
picture_generation_client_with_timeout(PICTURE_GENERATION_TIMEOUT_SECS)
}
+1
View File
@@ -1689,6 +1689,7 @@ mod tests {
first_byte_timeout_secs: 30,
max_retries: 3,
proxy_log_retention_days: 7,
template_proxy_url: None,
},
comfyui: Default::default(),
},
+3 -1
View File
@@ -1582,7 +1582,9 @@ async fn official_workflow_template_asset(
} else {
format!("{}/{}", OFFICIAL_WORKFLOW_TEMPLATES_BASE, encoded_path)
};
let mut request = reqwest::Client::new().get(url);
let mut request =
crate::template_http::client(&state.config, state.config.proxy.upstream_timeout_secs)
.get(url);
if state.config.comfyui.uses_cloud_backend() {
if let Some(api_key) = state
.config