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