diff options
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index db0fc93..82d6b02 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,9 +1,3 @@ | |||
1 | use std::{io::Write, fs::File}; | ||
2 | |||
3 | use reqwest::Client; | ||
4 | |||
5 | use futures_util::StreamExt; | ||
6 | |||
7 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | 1 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
8 | 2 | ||
9 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 3 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
@@ -16,9 +10,11 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
16 | Ok(()) | 10 | Ok(()) |
17 | } | 11 | } |
18 | 12 | ||
19 | async fn download_links(config: Cfg, input: Input, current_list: List, links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 13 | async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { |
20 | 14 | println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); | |
21 | let dl_path = String::from(&config.downloads); | 15 | //TODO copy dl from update if possible |
16 | /* | ||
17 | let dl_path = String::from(¤t_list.download_folder); | ||
22 | 18 | ||
23 | if input.clean { | 19 | if input.clean { |
24 | let dl_path = ¤t_list.download_folder; | 20 | let dl_path = ¤t_list.download_folder; |
@@ -28,28 +24,7 @@ async fn download_links(config: Cfg, input: Input, current_list: List, links: Ve | |||
28 | std::fs::remove_file(entry.path())?; | 24 | std::fs::remove_file(entry.path())?; |
29 | } | 25 | } |
30 | } | 26 | } |
27 | */ | ||
31 | 28 | ||
32 | for link in links { | 29 | Ok(String::new()) |
33 | let filename = link.split('/').last().unwrap(); | ||
34 | let dl_path_file = format!("{}/{}", config.downloads, filename); | ||
35 | println!("Downloading {}", link); | ||
36 | |||
37 | let res = Client::new() | ||
38 | .get(String::from(&link)) | ||
39 | .send() | ||
40 | .await | ||
41 | .or(Err(format!("Failed to GET from '{}'", &link)))?; | ||
42 | |||
43 | // download chunks | ||
44 | let mut file = File::create(String::from(&dl_path_file)).or(Err(format!("Failed to create file '{}'", dl_path_file)))?; | ||
45 | let mut stream = res.bytes_stream(); | ||
46 | |||
47 | while let Some(item) = stream.next().await { | ||
48 | let chunk = item.or(Err("Error while downloading file"))?; | ||
49 | file.write_all(&chunk) | ||
50 | .or(Err("Error while writing to file"))?; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | Ok(dl_path) | ||
55 | } | 30 | } |