summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-07 22:29:35 +0100
committerfxqnlr <[email protected]>2022-11-07 22:29:35 +0100
commit889dc4f87b05d838b25428478a8c42dac454a5cf (patch)
treec4b09ae53a74a7f0afc1e095a4b66a1b00e67244 /src/commands/update.rs
parentea50af892c4268ae06f6df40ee435eadd076228d (diff)
downloadmodlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar
modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar.gz
modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.zip
finished rusqlite; added all db tests
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index d278a78..e383eae 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -4,7 +4,7 @@ use reqwest::Client;
4 4
5use futures_util::StreamExt; 5use futures_util::StreamExt;
6 6
7use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, get_versions, get_list_version, change_list_versions}, List}; 7use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions}, List};
8 8
9pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 9pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
10 10
@@ -12,7 +12,7 @@ pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
12 12
13 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; 13 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?;
14 14
15 let mut versions = get_versions(config.clone(), mods.clone())?; 15 let mut versions = mods_get_versions(config.clone(), mods.clone())?;
16 versions.sort_by_key(|ver| ver.mod_id.clone()); 16 versions.sort_by_key(|ver| ver.mod_id.clone());
17 17
18 let mut projects = projects(String::from(&config.apis.modrinth), mods).await; 18 let mut projects = projects(String::from(&config.apis.modrinth), mods).await;
@@ -54,12 +54,15 @@ async fn specific_update(config: Cfg, list: List, project: Project) -> Result<Ve
54 } 54 }
55 55
56 let mut current: Vec<Version> = vec![]; 56 let mut current: Vec<Version> = vec![];
57 if versions.join("|") != get_list_version(config.clone(), list.clone(), String::from(&project.id))? { 57 if versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))? {
58 //get new versions 58 //get new versions
59 print!(" | getting new version"); 59 print!(" | getting new version");
60 let current_str = extract_current_version(applicable_versions.clone())?; 60 let current_str = extract_current_version(applicable_versions.clone())?;
61 current.push(applicable_versions.into_iter().find(|ver| ver.id == current_str).unwrap()); 61 let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?;
62 change_list_versions(config, list, current_str, versions, project.id)?; 62 current.push(current_ver.clone());
63
64 let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url;
65 userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?;
63 } 66 }
64 67
65 if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) }; 68 if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) };