diff --git a/src/commands/download.rs b/src/commands/download.rs index 9f93c50..556f458 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -3,6 +3,8 @@ use crate::utils; use crate::structs; use std::env; +use std::fs::File; +use std::io::Write; use std::sync::Arc; use std::path::Path; use std::process::exit; @@ -94,7 +96,7 @@ pub async fn run(args: env::Args) { let mut tmp_file_path = file_path.clone(); tmp_file_path.push_str(".tmp"); loop { - match utils::download_file(cloned_client.clone(), &url, &tmp_file_path).await { + match download_file(cloned_client.clone(), &url, &tmp_file_path).await { Ok(success) => { if success { break; @@ -113,3 +115,19 @@ pub async fn run(args: env::Args) { handle.await.unwrap(); } } + +async fn download_file(client: reqwest::Client, url: &str, file_name: &str) -> Result { + let resp = client.get(url) + .send() + .await?; + Ok(match resp.headers().get("Content-Type") { + Some(header) if header.to_str().unwrap_or_default().starts_with("image/") => { + let bytes = resp.bytes().await?; + let mut file = File::create(&file_name).unwrap(); + file.write_all(&bytes).unwrap(); + true + }, + _ => false + }) +} + diff --git a/src/utils.rs b/src/utils.rs index 91defeb..e6971b5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,22 +1,4 @@ use std::env; -use std::fs::File; -use std::io::Write; -extern crate reqwest; - -pub async fn download_file(client: reqwest::Client, url: &str, file_name: &str) -> Result { - let resp = client.get(url) - .send() - .await?; - Ok(match resp.headers().get("Content-Type") { - Some(header) if header.to_str().unwrap_or_default().starts_with("image/") => { - let bytes = resp.bytes().await?; - let mut file = File::create(&file_name).unwrap(); - file.write_all(&bytes).unwrap(); - true - }, - _ => false - }) -} pub fn get_arg_sauces(args: env::Args) -> Result, String> { let mut sauces: Vec = Vec::new();