From 3320da719669f37dd5f55693b4d76edb27dbce02 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 31 Oct 2022 13:01:06 +0100 Subject: modlist --- src/apis/mod.rs | 1 + src/apis/modrinth.rs | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/apis/mod.rs create mode 100644 src/apis/modrinth.rs (limited to 'src/apis') diff --git a/src/apis/mod.rs b/src/apis/mod.rs new file mode 100644 index 0000000..749d914 --- /dev/null +++ b/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod modrinth; diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs new file mode 100644 index 0000000..ce9fdd4 --- /dev/null +++ b/src/apis/modrinth.rs @@ -0,0 +1,104 @@ +use serde::{Deserialize, Serialize}; + +async fn get(path: String) -> Result, Box> { + dbg!(&path); + let api = String::from("https://api.modrinth.com/v2/"); + //let api = String::from("localhost:8080/"); + //let api = String::from("https://www.rust-lang.org/"); + let url = format!(r#"{}{}"#, api, path); + + println!("{}", &url); + + + let data = reqwest::get(r#"https://api.modrinth.com/v2/projects?ids=["kYuIpRLv","89Wsn8GD"]"#) + .await? + .bytes() + .await? + .to_vec(); + + //println!("body = {:?}", data); + + Ok(data) +} + +#[derive(Debug, Deserialize)] +pub struct Project { + pub slug: String, + pub title: String, + pub description: String, + pub categories: Vec, + pub client_side: Side, + pub server_side: Side, + pub body: String, + pub additional_categories: Option>, + pub project_type: Type, + pub downloads: u32, + pub icon_url: Option, + pub id: String, + pub team: String, + pub moderator_message: Option, + pub published: String, + pub updated: String, + pub approved: Option, + pub followers: u32, + pub status: Status, + pub license: License, + pub versions: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct License { + pub id: String, + pub name: String, + pub url: Option, +} + +#[derive(Debug, Deserialize)] +pub struct ModeratorMessage { + pub message: String, + pub body: Option, +} + +#[allow(non_camel_case_types)] +#[derive(Debug, Deserialize)] +pub enum Side { + required, + optional, + unsupported +} + +#[allow(non_camel_case_types)] +#[derive(Debug, Deserialize)] +pub enum Type { + r#mod, + modpack, + recourcepack +} + +#[allow(non_camel_case_types)] +#[derive(Debug, Deserialize)] +pub enum Status { + approved, + rejected, + draft, + unlisted, + archived, + processing, + unknown +} +pub async fn project(name: &str) -> Project { + let url = format!("project/{}", name); + let data = get(url); + + serde_json::from_slice(&data.await.unwrap()).unwrap() +} + +pub async fn projects(ids: Vec<&str>) -> Vec { + let all = ids.join(r#"",""#); + let url = format!(r#"projects?ids=["{}"]"#, all); + println!("{}", url); + + let data = get(url); + + serde_json::from_slice(&data.await.unwrap()).unwrap() +} -- cgit v1.2.3