diff options
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 16 |
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 @@ | |||
1 | use std::io::{Error, ErrorKind}; | ||
2 | use chrono::{DateTime, FixedOffset}; | 1 | use chrono::{DateTime, FixedOffset}; |
3 | use reqwest::Client; | 2 | use reqwest::Client; |
4 | use serde::Deserialize; | 3 | use serde::Deserialize; |
5 | 4 | ||
6 | use crate::{Modloader, List}; | 5 | use crate::{Modloader, List, error::{MLE, MLError, ErrorType}}; |
7 | 6 | ||
8 | #[derive(Debug, Deserialize, Clone)] | 7 | #[derive(Debug, Deserialize, Clone)] |
9 | pub struct Project { | 8 | pub struct Project { |
@@ -142,7 +141,7 @@ pub async fn project(api: String, name: &str) -> Project { | |||
142 | } | 141 | } |
143 | 142 | ||
144 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { | 143 | pub 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 | ||
180 | pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { | 179 | pub 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 | |||
198 | pub enum MCVersionType { | 197 | pub 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 | } |