From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/apis/modrinth.rs | 56 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'src/apis') diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index bb5ee19..9afe7f3 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -2,7 +2,10 @@ use chrono::{DateTime, FixedOffset}; use reqwest::Client; use serde::Deserialize; -use crate::{Modloader, List, error::{MLE, MLError, ErrorType}}; +use crate::{ + error::{ErrorType, MLError, MLE}, + List, Modloader, +}; #[derive(Debug, Deserialize, Clone)] pub struct Project { @@ -47,7 +50,7 @@ pub struct ModeratorMessage { pub enum Side { required, optional, - unsupported + unsupported, } #[allow(non_camel_case_types)] @@ -55,7 +58,7 @@ pub enum Side { pub enum Type { r#mod, modpack, - recourcepack + recourcepack, } #[allow(non_camel_case_types)] @@ -63,9 +66,11 @@ pub enum Type { pub enum Status { approved, rejected, - draft, unlisted, archived, + draft, + unlisted, + archived, processing, - unknown + unknown, } #[derive(Debug, Clone, Deserialize)] @@ -90,7 +95,7 @@ pub struct Version { pub enum VersionType { release, beta, - alpha + alpha, } #[derive(Debug, Clone, Deserialize)] @@ -110,22 +115,19 @@ pub struct Hash { async fn get(api: &str, path: String) -> Result>, Box> { let url = format!(r#"{}{}"#, api, path); - + let client = Client::builder() - .user_agent(format!("fxqnlr/modlistcli/{} (fxqnlr@gmail.com)", env!("CARGO_PKG_VERSION"))) + .user_agent(format!( + "fxqnlr/modlistcli/{} (fxqnlr@gmail.com)", + env!("CARGO_PKG_VERSION") + )) .build()?; - let res = client.get(url) - .send() - .await?; - + let res = client.get(url).send().await?; + let mut data: Option> = None; if res.status() == 200 { - data = Some(res - .bytes() - .await? - .to_vec() - ); + data = Some(res.bytes().await?.to_vec()); } Ok(data) @@ -143,7 +145,7 @@ pub async fn projects(api: &str, ids: Vec) -> Vec { let url = format!(r#"projects?ids=["{}"]"#, all); let data = get(api, url).await.unwrap().unwrap(); - + serde_json::from_slice(&data).unwrap() } @@ -154,7 +156,10 @@ pub async fn versions(api: &str, id: String, list: List) -> Vec { Modloader::Fabric => String::from("fabric"), }; - let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, list.mc_version); + let url = format!( + r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, + id, loaderstr, list.mc_version + ); let data = get(api, url).await.unwrap(); @@ -185,7 +190,7 @@ pub fn extract_current_version(versions: Vec) -> MLE { times.sort_by_key(|t| t.1); times.reverse(); Ok(times[0].0.to_string()) - }, + } _ => panic!("available_versions should never be negative"), } } @@ -205,16 +210,19 @@ pub struct MCVersion { } pub async fn get_minecraft_version(api: &str, version: MCVersionType) -> String { - let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap(); + let data = get(api, String::from("tag/game_version")) + .await + .unwrap() + .unwrap(); let mc_versions: Vec = serde_json::from_slice(&data).unwrap(); let ver = match version { MCVersionType::Release => { let mut i = 0; - while !mc_versions[i].major { + while !mc_versions[i].major { i += 1; - }; + } &mc_versions[i] - }, + } MCVersionType::Latest => &mc_versions[0], MCVersionType::Specific => { println!("Not inplemented"); -- cgit v1.2.3