summaryrefslogtreecommitdiff
path: root/src/apis
diff options
context:
space:
mode:
Diffstat (limited to 'src/apis')
-rw-r--r--src/apis/modrinth.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index 78073e6..36ab5df 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -1,9 +1,8 @@
1use std::io::{Error, ErrorKind};
2use chrono::{DateTime, FixedOffset}; 1use chrono::{DateTime, FixedOffset};
3use reqwest::Client; 2use reqwest::Client;
4use serde::Deserialize; 3use serde::Deserialize;
5 4
6use crate::{Modloader, List}; 5use crate::{Modloader, List, error::{MLE, MLError, ErrorType}};
7 6
8#[derive(Debug, Deserialize, Clone)] 7#[derive(Debug, Deserialize, Clone)]
9pub struct Project { 8pub struct Project {
@@ -142,7 +141,7 @@ pub async fn project(api: String, name: &str) -> Project {
142} 141}
143 142
144pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { 143pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> {
145 println!("Getting versions for all mods from modrinth"); 144 println!("\tGet versions from modrinth\n");
146 let all = ids.join(r#"",""#); 145 let all = ids.join(r#"",""#);
147 let url = format!(r#"projects?ids=["{}"]"#, all); 146 let url = format!(r#"projects?ids=["{}"]"#, all);
148 147
@@ -177,9 +176,9 @@ pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version
177 serde_json::from_slice(&data).unwrap() 176 serde_json::from_slice(&data).unwrap()
178} 177}
179 178
180pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { 179pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> {
181 match versions.len() { 180 match versions.len() {
182 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), 181 0 => Err(MLError::new(ErrorType::ModError, "NO_VERSIONS_AVAILABLE")),
183 1.. => { 182 1.. => {
184 let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; 183 let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![];
185 for ver in versions { 184 for ver in versions {
@@ -188,7 +187,7 @@ pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn
188 } 187 }
189 times.sort_by_key(|t| t.1); 188 times.sort_by_key(|t| t.1);
190 times.reverse(); 189 times.reverse();
191 println!("Current Version: {}", times[0].0); 190 println!("\t └New current version: {}", times[0].0);
192 Ok(times[0].0.to_string()) 191 Ok(times[0].0.to_string())
193 }, 192 },
194 _ => panic!("available_versions should never be negative"), 193 _ => panic!("available_versions should never be negative"),
@@ -198,6 +197,7 @@ pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn
198pub enum MCVersionType { 197pub enum MCVersionType {
199 Release, 198 Release,
200 Latest, 199 Latest,
200 Specific,
201} 201}
202 202
203#[derive(Debug, Deserialize)] 203#[derive(Debug, Deserialize)]
@@ -220,6 +220,10 @@ pub async fn get_minecraft_version(api: String, version: MCVersionType) -> Strin
220 &mc_versions[i] 220 &mc_versions[i]
221 }, 221 },
222 MCVersionType::Latest => &mc_versions[0], 222 MCVersionType::Latest => &mc_versions[0],
223 MCVersionType::Specific => {
224 println!("Not inplemented");
225 &mc_versions[0]
226 }
223 }; 227 };
224 String::from(&ver.version) 228 String::from(&ver.version)
225} 229}