Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
feat: implement direct download functionality with progress tracking
Tonhocd3b8949e55d
diff --git a/src-tauri/src/core/direct_downloader.rs b/src-tauri/src/core/direct_downloader.rsnew file mode 100644index 00000000..401cf897--- /dev/null+++ b/src-tauri/src/core/direct_downloader.rs@@ -0,0 +1,51 @@+use std::path::Path;++use anyhow::anyhow;+use futures::StreamExt;+use tokio::io::AsyncWriteExt;+use tokio::sync::mpsc;++pub async fn download_direct(+ client: &reqwest::Client,+ url: &str,+ output: &Path,+ progress_tx: mpsc::Sender<f64>,+) -> anyhow::Result<u64> {+ let response = client.get(url).send().await?;++ if !response.status().is_success() {+ return Err(anyhow!(+ "HTTP {} ao baixar {}",+ response.status(),+ url+ ));+ }++ let total_size = response.content_length();++ if let Some(parent) = output.parent() {+ tokio::fs::create_dir_all(parent).await?;+ }++ let mut file = tokio::fs::File::create(output).await?;+ let mut downloaded: u64 = 0;+ let mut stream = response.bytes_stream();++ while let Some(chunk) = stream.next().await {+ let chunk = chunk?;+ file.write_all(&chunk).await?;+ downloaded += chunk.len() as u64;++ if let Some(total) = total_size {+ if total > 0 {+ let percent = (downloaded as f64 / total as f64) * 100.0;+ let _ = progress_tx.send(percent).await;+ }+ }+ }++ file.flush().await?;+ let _ = progress_tx.send(100.0).await;++ Ok(downloaded)+}