diff options
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 0c3eca5..c71b47f 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::io::{Error, ErrorKind}; | ||
2 | use chrono::{DateTime, FixedOffset}; | ||
1 | use serde::Deserialize; | 3 | use serde::Deserialize; |
2 | 4 | ||
3 | use crate::{Modloader, List}; | 5 | use crate::{Modloader, List}; |
@@ -153,3 +155,24 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | |||
153 | 155 | ||
154 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 156 | serde_json::from_slice(&data.await.unwrap()).unwrap() |
155 | } | 157 | } |
158 | |||
159 | pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { | ||
160 | match versions.len() { | ||
161 | 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), | ||
162 | //TODO compare publish dates | ||
163 | 1.. => { | ||
164 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; | ||
165 | for ver in versions { | ||
166 | let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?; | ||
167 | times.push((ver.id, stamp)) | ||
168 | } | ||
169 | dbg!(×); | ||
170 | times.sort_by_key(|t| t.1); | ||
171 | times.reverse(); | ||
172 | dbg!(×); | ||
173 | println!("CW: {}", times[0].0); | ||
174 | Ok(times[0].0.to_string()) | ||
175 | }, | ||
176 | _ => panic!("available_versions should never be negative"), | ||
177 | } | ||
178 | } | ||