feat(download): 走系统网络栈(Rust)+并发默认30可调;修并发限制从未生效
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 48s

This commit is contained in:
qiqi committed 2026-12-03 17:29:48 +08:00
1 parent 3894c697ac
commit 2ff1ccd2d1
8 files changed
+123 -12

No files matched your search

+37 -1
View File
@@ -292,6 +292,41 @@ fn do_thumbs(src: &str, jobs: &[ThumbJob]) -> Result<serde_json::Value, String>
Ok(serde_json::json!({ "ok": true, "files": out }))
}
// 2026-12-03(用户裁定):图片下载走系统网络栈。
// 为什么:WebView 的 fetch 是跨域 XHR,图床/CDN 会限速、挂起或按防盗链策略直接不回包
// (实测任务队列卡在 55% 不动);Rust 侧 reqwest 与浏览器导航同一栈,不受 CORS 约束。
// 返回 base64 + mime + 字节数;不写盘、不解析图片,调用方自己决定落到哪里。
#[tauri::command]
async fn fetch_image_b64(url: String, referer: Option<String>) -> Result<serde_json::Value, String> {
use base64::Engine as _;
let client = tauri_plugin_http::reqwest::Client::builder()
.connect_timeout(std::time::Duration::from_secs(15))
.timeout(std::time::Duration::from_secs(120))
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
.build()
.map_err(|e| e.to_string())?;
let mut req = client.get(&url);
if let Some(r) = referer {
if !r.is_empty() {
req = req.header(tauri_plugin_http::reqwest::header::REFERER, r);
}
}
let resp = req.send().await.map_err(|e| e.to_string())?;
let status = resp.status();
if !status.is_success() {
return Ok(serde_json::json!({ "ok": false, "error": format!("http-{}", status.as_u16()) }));
}
let mime = resp
.headers()
.get(tauri_plugin_http::reqwest::header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream")
.to_string();
let bytes = resp.bytes().await.map_err(|e| e.to_string())?;
let b64 = base64::engine::general_purpose::STANDARD.encode(&bytes);
Ok(serde_json::json!({ "ok": true, "mime": mime, "bytes": bytes.len(), "b64": b64 }))
}
#[tauri::command]
async fn img_thumbs(src: String, jobs: Vec<ThumbJob>) -> Result<serde_json::Value, String> {
tauri::async_runtime::spawn_blocking(move || do_thumbs(&src, &jobs))
@@ -2055,7 +2090,8 @@ pub fn run() {
app_memory_mb,
app_memory_tree_mb,
app_memory_breakdown,
img_thumbs
img_thumbs,
fetch_image_b64
])
.setup(|app| {
if cfg!(debug_assertions) {