summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-01-11 17:21:08 +0100
committerFxQnLr <[email protected]>2023-01-11 17:21:08 +0100
commit92bda65a9983e60036b3d49333e9bfe9bcd0543f (patch)
tree423494ff75fe6ef7fecb30fb2188ab6af8178277
parent89193143f90e1b8cbb91445d14942fa39509acbb (diff)
downloadmodlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.tar
modlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.tar.gz
modlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.zip
begin of mc_version api impl
-rw-r--r--data.db0
-rw-r--r--src/apis/modrinth.rs29
-rw-r--r--src/commands/list.rs8
3 files changed, 33 insertions, 4 deletions
diff --git a/data.db b/data.db
deleted file mode 100644
index e69de29..0000000
--- a/data.db
+++ /dev/null
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index 3880fa0..78073e6 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -194,3 +194,32 @@ pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn
194 _ => panic!("available_versions should never be negative"), 194 _ => panic!("available_versions should never be negative"),
195 } 195 }
196} 196}
197
198pub enum MCVersionType {
199 Release,
200 Latest,
201}
202
203#[derive(Debug, Deserialize)]
204pub struct MCVersion {
205 pub version: String,
206 pub version_type: String,
207 pub date: String,
208 pub major: bool,
209}
210
211pub async fn get_minecraft_version(api: String, version: MCVersionType) -> String {
212 let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap();
213 let mc_versions: Vec<MCVersion> = serde_json::from_slice(&data).unwrap();
214 let ver = match version {
215 MCVersionType::Release => {
216 let mut i = 0;
217 while !mc_versions[i].major {
218 i += 1;
219 };
220 &mc_versions[i]
221 },
222 MCVersionType::Latest => &mc_versions[0],
223 };
224 String::from(&ver.version)
225}
diff --git a/src/commands/list.rs b/src/commands/list.rs
index 526b434..a02f8b1 100644
--- a/src/commands/list.rs
+++ b/src/commands/list.rs
@@ -1,6 +1,6 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, Subcmd}, cmd_update, error::{MLE, ErrorType, MLError}}; 3use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, Subcmd}, cmd_update, error::{MLE, ErrorType, MLError}, modrinth::MCVersionType};
4 4
5#[derive(Debug, Clone, PartialEq, Eq)] 5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct List { 6pub struct List {
@@ -26,7 +26,7 @@ pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::E
26 remove(config, input.args.ok_or("")?) 26 remove(config, input.args.ok_or("")?)
27 }, 27 },
28 Subcmd::Version => { 28 Subcmd::Version => {
29 match version(config, input.args.ok_or("NO_VERSION")?).await { 29 match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await {
30 Ok(..) => Ok(()), 30 Ok(..) => Ok(()),
31 Err(e) => Err(Box::new(e)) 31 Err(e) => Err(Box::new(e))
32 } 32 }
@@ -85,10 +85,10 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro
85/// 85///
86/// * `config` - The current config 86/// * `config` - The current config
87/// * `args` - All args, to extract the new version 87/// * `args` - All args, to extract the new version
88async fn version(config: Cfg, args: Vec<String>) -> MLE<()> { 88async fn version(config: Cfg, args: Option<Vec<String>>, version_type: Option<MCVersionType>) -> MLE<()> {
89 let current_list = lists_get(config.clone(), config_get_current_list(config.clone())?)?; 89 let current_list = lists_get(config.clone(), config_get_current_list(config.clone())?)?;
90 90
91 lists_version(config.clone(), String::from(&current_list.id), String::from(&args[0]))?; 91 lists_version(config.clone(), String::from(&current_list.id), String::from(&args.unwrap()[0]))?;
92 //update the list & with -- args 92 //update the list & with -- args
93 cmd_update(config, vec![current_list], true, true, false).await 93 cmd_update(config, vec![current_list], true, true, false).await
94} 94}