mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 17:14:36 +01:00
(misc) Enable window.startDragging for Tauri
This commit is contained in:
25
src-tauri/src/http.rs
Normal file
25
src-tauri/src/http.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use core::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
/// Downloads a file from the given URL.
|
||||
/// Saves it to the specified file.
|
||||
/// This will overwrite the file if it already exists.
|
||||
/// url: The URL to download from.
|
||||
/// to_file: The file to save to.
|
||||
#[tauri::command]
|
||||
pub async fn download_file(url: String, to_file: String) -> Result<String, Box<dyn Error>> {
|
||||
let mut response = reqwest::get(&url).await?;
|
||||
let mut dest = {
|
||||
let fname = Path::new(&to_file);
|
||||
match File::create(&fname) {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Err(Box::new(e)),
|
||||
}
|
||||
};
|
||||
while let Some(chunk) = response.chunk().await? {
|
||||
dest.write_all(&chunk).await?;
|
||||
}
|
||||
Ok("Downloaded".to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user