Skip to content

Commit

Permalink
Update download.rs
Browse files Browse the repository at this point in the history
Signed-off-by: ArchBlood <35392110+ArchBlood@users.noreply.github.com>
  • Loading branch information
ArchBlood authored Dec 22, 2024
1 parent d91428d commit adc070d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use serde::Deserialize;
use reqwest::blocking;
use zip;
use std::time::Duration;

// Define a struct to deserialize the JSON configuration
#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -47,11 +48,16 @@ fn load_config(path: &str) -> io::Result<Config> {
fn download_file(url: &str, output_path: &Path) -> io::Result<()> {
println!("Downloading file from: {}", url);

let client = blocking::Client::new();
let client = blocking::Client::builder()
.timeout(Duration::from_secs(60)) // Add timeout for the request
.danger_accept_invalid_certs(false) // Make sure SSL validation is done (set to true for secure config)
.build()
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to create HTTP client: {}", e)))?;

let mut response = client
.get(url)
.send()
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to send request: {}", e)))?;

if !response.status().is_success() {
return Err(io::Error::new(
Expand All @@ -73,7 +79,7 @@ fn extract_zip(zip_path: &Path, extract_dir: &Path) -> io::Result<()> {

let zip_file = File::open(zip_path)?;
let mut archive = zip::ZipArchive::new(zip_file)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, format!("Failed to read ZIP archive: {}", e)))?;

for i in 0..archive.len() {
let mut file = archive.by_index(i)?;
Expand Down

0 comments on commit adc070d

Please sign in to comment.