diff options
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 13ba0e1..b0efdc2 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use crate::{modrinth::Version, files::download_file}; | ||
1 | #[allow(unused_imports)] | 2 | #[allow(unused_imports)] |
2 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | 3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
3 | 4 | ||
@@ -32,3 +33,19 @@ async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links | |||
32 | 33 | ||
33 | Ok(String::new()) | 34 | Ok(String::new()) |
34 | } | 35 | } |
36 | |||
37 | pub async fn download_versions(current_list: List, versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { | ||
38 | |||
39 | let dl_path = String::from(¤t_list.download_folder); | ||
40 | |||
41 | for ver in versions { | ||
42 | let primary_file = ver.files.into_iter().find(|file| file.primary).unwrap(); | ||
43 | let mut splitname: Vec<&str> = primary_file.filename.split('.').collect(); | ||
44 | let extension = splitname.pop().ok_or("NO_FILE_EXTENSION")?; | ||
45 | let filename = format!("{}.mr{}.{}", splitname.join("."), ver.id, extension); | ||
46 | download_file(primary_file.url, current_list.clone().download_folder, filename).await?; | ||
47 | } | ||
48 | |||
49 | Ok(dl_path) | ||
50 | } | ||
51 | |||