summaryrefslogtreecommitdiff
path: root/src/apis/modrinth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/apis/modrinth.rs')
-rw-r--r--src/apis/modrinth.rs29
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
198pub enum MCVersionType {
199 Release,
200 Latest,
201}
202
203#[derive(Debug, Deserialize)]
204pub struct MCVersion {
205 pub version: String,
206 pub version_type: String,
207 pub date: String,
208 pub major: bool,
209}
210
211pub 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}