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 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/db.rs | 0 src/lib.rs | 4 ++ src/main.rs | 7 ++++ src/update.rs | 8 ++++ 6 files changed, 124 insertions(+) create mode 100644 src/apis/mod.rs create mode 100644 src/apis/modrinth.rs create mode 100644 src/db.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 src/update.rs (limited to 'src') 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() +} diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..cbb761c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ +pub mod update; +pub mod apis; + +pub use apis::*; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8d1a1bd --- /dev/null +++ b/src/main.rs @@ -0,0 +1,7 @@ +use modlist::modrinth::projects; + +#[tokio::main] +async fn main() { + //projects(vec!["kYuIpRLv", "89Wsn8GD"]); + println!("{:?}", projects(vec!["kYuIpRLv", "89Wsn8GD"]).await); +} diff --git a/src/update.rs b/src/update.rs new file mode 100644 index 0000000..2e70f43 --- /dev/null +++ b/src/update.rs @@ -0,0 +1,8 @@ +pub fn update_mods() { + +} + +fn get_version(link: String) { + + +} -- cgit v1.2.3