diff options
author | FxQnLr <[email protected]> | 2023-01-11 17:21:08 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-01-11 17:21:08 +0100 |
commit | 92bda65a9983e60036b3d49333e9bfe9bcd0543f (patch) | |
tree | 423494ff75fe6ef7fecb30fb2188ab6af8178277 /src/apis | |
parent | 89193143f90e1b8cbb91445d14942fa39509acbb (diff) | |
download | modlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.tar modlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.tar.gz modlist-92bda65a9983e60036b3d49333e9bfe9bcd0543f.zip |
begin of mc_version api impl
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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 | |||
198 | pub enum MCVersionType { | ||
199 | Release, | ||
200 | Latest, | ||
201 | } | ||
202 | |||
203 | #[derive(Debug, Deserialize)] | ||
204 | pub struct MCVersion { | ||
205 | pub version: String, | ||
206 | pub version_type: String, | ||
207 | pub date: String, | ||
208 | pub major: bool, | ||
209 | } | ||
210 | |||
211 | pub 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 | } | ||