mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
fixes
This commit is contained in:
@@ -15,7 +15,9 @@ use tauri::{
|
||||
#[tauri::command]
|
||||
pub async fn download_file(url: &str, path: &str) -> Result<(), String> {
|
||||
// Reqwest setup
|
||||
let res = reqwest::get(url).await.or(Err(format!("Failed to get {}", url)))?;
|
||||
let res = reqwest::get(url)
|
||||
.await
|
||||
.or(Err(format!("Failed to get {}", url)))?;
|
||||
let total_size = res
|
||||
.content_length()
|
||||
.ok_or(format!("Failed to get content length from '{}'", &url))?;
|
||||
@@ -29,15 +31,22 @@ pub async fn download_file(url: &str, path: &str) -> Result<(), String> {
|
||||
|
||||
// Await chunks
|
||||
while let Some(item) = stream.next().await {
|
||||
let chunk = item.or(Err(format!("Error while downloading file")));
|
||||
// Write chunk
|
||||
file.write_all(&chunk)
|
||||
.or(Err(format!("Error while writing to file")))?;
|
||||
let chunk = item.or(Err(format!("Error while downloading file"))).unwrap();
|
||||
let vect = &chunk.to_vec()[..];
|
||||
|
||||
// Write bytes
|
||||
file.write_all(&vect)
|
||||
.or(Err(format!("Error while writing file")))?;
|
||||
|
||||
// New progress
|
||||
let new = min(downloaded + (chunk.len() as u64), total_size);
|
||||
downloaded = new;
|
||||
|
||||
// Create event to send to frontend
|
||||
}
|
||||
|
||||
// One more "finish" event
|
||||
|
||||
// We are done
|
||||
return Ok(());
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
mod downloader;
|
||||
mod proxy;
|
||||
|
||||
use tauri::{
|
||||
|
||||
Reference in New Issue
Block a user