From 477e0ecbb7bb34b581c518bfc2bc7ebc210b4673 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sat, 19 Nov 2022 21:31:37 +0100 Subject: added clean to download --- src/commands/download.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/commands') diff --git a/src/commands/download.rs b/src/commands/download.rs index 993294b..db0fc93 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -4,22 +4,31 @@ use reqwest::Client; use futures_util::StreamExt; -use crate::{get_current_list, config::Cfg, db::userlist_get_all_downloads}; +use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; -pub async fn download(config: Cfg) -> Result<(), Box> { +pub async fn download(config: Cfg, input: Input) -> Result<(), Box> { let list = get_current_list(config.clone())?; - let links = userlist_get_all_downloads(config.clone(), list.id)?; + let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; - download_links(config, links).await?; + download_links(config, input, list, links).await?; Ok(()) } -async fn download_links(config: Cfg, links: Vec) -> Result> { +async fn download_links(config: Cfg, input: Input, current_list: List, links: Vec) -> Result> { let dl_path = String::from(&config.downloads); + if input.clean { + let dl_path = ¤t_list.download_folder; + println!("Cleaning {}", dl_path); + for entry in std::fs::read_dir(dl_path)? { + let entry = entry?; + std::fs::remove_file(entry.path())?; + } + } + for link in links { let filename = link.split('/').last().unwrap(); let dl_path_file = format!("{}/{}", config.downloads, filename); -- cgit v1.2.3