diff options
author | fxqnlr <[email protected]> | 2022-11-07 22:29:35 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-07 22:29:35 +0100 |
commit | 889dc4f87b05d838b25428478a8c42dac454a5cf (patch) | |
tree | c4b09ae53a74a7f0afc1e095a4b66a1b00e67244 /src/commands/setup.rs | |
parent | ea50af892c4268ae06f6df40ee435eadd076228d (diff) | |
download | modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar.gz modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.zip |
finished rusqlite; added all db tests
Diffstat (limited to 'src/commands/setup.rs')
-rw-r--r-- | src/commands/setup.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/commands/setup.rs b/src/commands/setup.rs index 0940959..8c0fcfd 100644 --- a/src/commands/setup.rs +++ b/src/commands/setup.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::{fs::File, path::Path, io::{Error, ErrorKind}}; | 1 | use std::{fs::File, path::Path, io::{Error, ErrorKind}}; |
2 | 2 | ||
3 | use crate::{config::Cfg, db::{db_setup, user_dbversion, create_dbversion, insert_column, get_lists, get_list, get_current_versions, insert_dl_link}, modrinth::get_raw_versions}; | 3 | use crate::{config::Cfg, db::{db_setup, s_config_get_version, s_config_create_version, s_insert_column, lists_get_all_ids, lists_get, userlist_get_all_current_version_ids, s_userlist_update_download}, modrinth::get_raw_versions}; |
4 | 4 | ||
5 | pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -10,7 +10,7 @@ pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
10 | return create(config, db_file); | 10 | return create(config, db_file); |
11 | } | 11 | } |
12 | 12 | ||
13 | match user_dbversion(config.clone()) { | 13 | match s_config_get_version(config.clone()) { |
14 | Ok(ver) => { | 14 | Ok(ver) => { |
15 | match ver.as_str() { | 15 | match ver.as_str() { |
16 | _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) | 16 | _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) |
@@ -29,26 +29,25 @@ fn create(config: Cfg, db_file: String) -> Result<(), Box<dyn std::error::Error> | |||
29 | } | 29 | } |
30 | 30 | ||
31 | async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 31 | async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { |
32 | let lists = get_lists(config.clone())?; | 32 | let lists = lists_get_all_ids(config.clone())?; |
33 | 33 | ||
34 | for list in lists { | 34 | for list in lists { |
35 | println!("Updating {}", list); | 35 | println!("Updating {}", list); |
36 | insert_column(config.clone(), String::from(&list), String::from("current_download"), String::new())?; | 36 | s_insert_column(config.clone(), String::from(&list), String::from("current_download"), String::new())?; |
37 | 37 | ||
38 | let full_list = get_list(config.clone(), String::from(&list))?; | 38 | let full_list = lists_get(config.clone(), String::from(&list))?; |
39 | 39 | ||
40 | let versions = get_current_versions(config.clone(), full_list.clone())?; | 40 | let versions = userlist_get_all_current_version_ids(config.clone(), full_list.clone().id)?; |
41 | 41 | ||
42 | let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await; | 42 | let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await; |
43 | 43 | ||
44 | for ver in raw_versions { | 44 | for ver in raw_versions { |
45 | println!("Adding link for {}", ver.project_id); | 45 | println!("Adding link for {}", ver.project_id); |
46 | let file = ver.files.into_iter().find(|f| f.primary).unwrap(); | 46 | let file = ver.files.into_iter().find(|f| f.primary).unwrap(); |
47 | insert_dl_link(config.clone(), full_list.clone(), ver.project_id, file.url)?; | 47 | s_userlist_update_download(config.clone(), String::from(&full_list.id), ver.project_id, file.url)?; |
48 | } | 48 | } |
49 | }; | 49 | }; |
50 | create_dbversion(config)?; | 50 | s_config_create_version(config)?; |
51 | |||
52 | 51 | ||
53 | Ok(()) | 52 | Ok(()) |
54 | } | 53 | } |