diff options
author | fxqnlr <[email protected]> | 2022-11-04 23:41:21 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-04 23:41:21 +0100 |
commit | 5d50f446a1a4612c0c931bdbc61f945760392f29 (patch) | |
tree | 44414994e19b41979a8a939b120ada0d1aa8a13a /src/apis/modrinth.rs | |
parent | 96cc5257de09682df345e768dc2a91303f9b36c9 (diff) | |
download | modlist-5d50f446a1a4612c0c931bdbc61f945760392f29.tar modlist-5d50f446a1a4612c0c931bdbc61f945760392f29.tar.gz modlist-5d50f446a1a4612c0c931bdbc61f945760392f29.zip |
"finished" update, added some tests
Diffstat (limited to 'src/apis/modrinth.rs')
-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 | } | ||