Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-avatar": "^1.1.11",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
"@radix-ui/react-label": "^2.1.8",
Expand All @@ -58,6 +59,7 @@
"@radix-ui/react-switch": "^1.2.6",
"@radix-ui/react-tabs": "^1.1.13",
"@radix-ui/react-toast": "^1.2.15",
"@radix-ui/react-tooltip": "^1.2.8",
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.3.3",
"class-variance-authority": "^0.7.1",
Expand Down
22 changes: 12 additions & 10 deletions src-tauri/src/services/tool/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ pub enum DownloadEvent {

/// 文件下载器
#[derive(Clone)]
pub struct FileDownloader {
client: reqwest::Client,
}
pub struct FileDownloader {}

impl FileDownloader {
pub fn new() -> Self {
Self {
client: crate::http_client::build_client()
.expect("Failed to create HTTP client for downloader"),
}
Self {}
}

/// 创建 HTTP 客户端(每次调用时动态创建,以确保使用最新的代理配置)
fn create_client() -> Result<reqwest::Client> {
crate::http_client::build_client()
.map_err(|e| anyhow::anyhow!("Failed to create HTTP client: {e}"))
}

/// 异步下载文件,支持进度回调
Expand All @@ -49,8 +50,8 @@ impl FileDownloader {
}

// 发起HTTP请求
let response = self
.client
let client = Self::create_client()?;
let response = client
.get(url)
.send()
.await
Expand Down Expand Up @@ -127,7 +128,8 @@ impl FileDownloader {

/// 获取文件大小(如果支持)
pub async fn get_file_size(&self, url: &str) -> Result<Option<u64>> {
match self.client.head(url).send().await {
let client = Self::create_client()?;
match client.head(url).send().await {
Ok(response) => Ok(response.content_length()),
Err(e) => {
// 如果HEAD请求失败,可能是服务器不支持HEAD请求,记录但不阻断下载
Expand Down
Loading
Loading