diff options
author | FxQnLr <[email protected]> | 2022-11-19 21:31:37 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-11-19 21:31:37 +0100 |
commit | 477e0ecbb7bb34b581c518bfc2bc7ebc210b4673 (patch) | |
tree | 2a1a883f785bfaf9d8aa20eb9a7c29737c01e07e /src/commands/download.rs | |
parent | fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 (diff) | |
download | modlist-477e0ecbb7bb34b581c518bfc2bc7ebc210b4673.tar modlist-477e0ecbb7bb34b581c518bfc2bc7ebc210b4673.tar.gz modlist-477e0ecbb7bb34b581c518bfc2bc7ebc210b4673.zip |
added clean to download
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 19 |
1 files changed, 14 insertions, 5 deletions
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; | |||
4 | 4 | ||
5 | use futures_util::StreamExt; | 5 | use futures_util::StreamExt; |
6 | 6 | ||
7 | use crate::{get_current_list, config::Cfg, db::userlist_get_all_downloads}; | 7 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
8 | 8 | ||
9 | pub async fn download(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 9 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
10 | let list = get_current_list(config.clone())?; | 10 | let list = get_current_list(config.clone())?; |
11 | 11 | ||
12 | let links = userlist_get_all_downloads(config.clone(), list.id)?; | 12 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; |
13 | 13 | ||
14 | download_links(config, links).await?; | 14 | download_links(config, input, list, links).await?; |
15 | 15 | ||
16 | Ok(()) | 16 | Ok(()) |
17 | } | 17 | } |
18 | 18 | ||
19 | async fn download_links(config: Cfg, links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 19 | async fn download_links(config: Cfg, input: Input, current_list: List, links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { |
20 | 20 | ||
21 | let dl_path = String::from(&config.downloads); | 21 | let dl_path = String::from(&config.downloads); |
22 | 22 | ||
23 | if input.clean { | ||
24 | let dl_path = ¤t_list.download_folder; | ||
25 | println!("Cleaning {}", dl_path); | ||
26 | for entry in std::fs::read_dir(dl_path)? { | ||
27 | let entry = entry?; | ||
28 | std::fs::remove_file(entry.path())?; | ||
29 | } | ||
30 | } | ||
31 | |||
23 | for link in links { | 32 | for link in links { |
24 | let filename = link.split('/').last().unwrap(); | 33 | let filename = link.split('/').last().unwrap(); |
25 | let dl_path_file = format!("{}/{}", config.downloads, filename); | 34 | let dl_path_file = format!("{}/{}", config.downloads, filename); |