summaryrefslogtreecommitdiff
path: root/src/commands/download.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-28 22:55:14 +0100
committerfxqnlr <[email protected]>2022-11-28 22:55:14 +0100
commitddde9204c72dd867f920f07f6483be03dda7cf68 (patch)
tree51ee1140311be4a82a7832bcef2772db7fd4e639 /src/commands/download.rs
parentd8cb7bc5f9c2e01c82f954427a60da6eaf0610ca (diff)
downloadmodlist-ddde9204c72dd867f920f07f6483be03dda7cf68.tar
modlist-ddde9204c72dd867f920f07f6483be03dda7cf68.tar.gz
modlist-ddde9204c72dd867f920f07f6483be03dda7cf68.zip
basically update impl; added "good" download;
auto dl on new mod; db to 0.4; etc
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r--src/commands/download.rs17
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 @@
1use crate::{modrinth::Version, files::download_file};
1#[allow(unused_imports)] 2#[allow(unused_imports)]
2use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; 3use 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
37pub async fn download_versions(current_list: List, versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> {
38
39 let dl_path = String::from(&current_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