summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apis/mod.rs1
-rw-r--r--src/apis/modrinth.rs104
-rw-r--r--src/db.rs0
-rw-r--r--src/lib.rs4
-rw-r--r--src/main.rs7
-rw-r--r--src/update.rs8
6 files changed, 124 insertions, 0 deletions
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 @@
1use serde::{Deserialize, Serialize};
2
3async fn get(path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
4 dbg!(&path);
5 let api = String::from("https://api.modrinth.com/v2/");
6 //let api = String::from("localhost:8080/");
7 //let api = String::from("https://www.rust-lang.org/");
8 let url = format!(r#"{}{}"#, api, path);
9
10 println!("{}", &url);
11
12
13 let data = reqwest::get(r#"https://api.modrinth.com/v2/projects?ids=["kYuIpRLv","89Wsn8GD"]"#)
14 .await?
15 .bytes()
16 .await?
17 .to_vec();
18
19 //println!("body = {:?}", data);
20
21 Ok(data)
22}
23
24#[derive(Debug, Deserialize)]
25pub struct Project {
26 pub slug: String,
27 pub title: String,
28 pub description: String,
29 pub categories: Vec<String>,
30 pub client_side: Side,
31 pub server_side: Side,
32 pub body: String,
33 pub additional_categories: Option<Vec<String>>,
34 pub project_type: Type,
35 pub downloads: u32,
36 pub icon_url: Option<String>,
37 pub id: String,
38 pub team: String,
39 pub moderator_message: Option<ModeratorMessage>,
40 pub published: String,
41 pub updated: String,
42 pub approved: Option<String>,
43 pub followers: u32,
44 pub status: Status,
45 pub license: License,
46 pub versions: Vec<String>,
47}
48
49#[derive(Debug, Deserialize)]
50pub struct License {
51 pub id: String,
52 pub name: String,
53 pub url: Option<String>,
54}
55
56#[derive(Debug, Deserialize)]
57pub struct ModeratorMessage {
58 pub message: String,
59 pub body: Option<String>,
60}
61
62#[allow(non_camel_case_types)]
63#[derive(Debug, Deserialize)]
64pub enum Side {
65 required,
66 optional,
67 unsupported
68}
69
70#[allow(non_camel_case_types)]
71#[derive(Debug, Deserialize)]
72pub enum Type {
73 r#mod,
74 modpack,
75 recourcepack
76}
77
78#[allow(non_camel_case_types)]
79#[derive(Debug, Deserialize)]
80pub enum Status {
81 approved,
82 rejected,
83 draft,
84 unlisted,
85 archived,
86 processing,
87 unknown
88}
89pub async fn project(name: &str) -> Project {
90 let url = format!("project/{}", name);
91 let data = get(url);
92
93 serde_json::from_slice(&data.await.unwrap()).unwrap()
94}
95
96pub async fn projects(ids: Vec<&str>) -> Vec<Project> {
97 let all = ids.join(r#"",""#);
98 let url = format!(r#"projects?ids=["{}"]"#, all);
99 println!("{}", url);
100
101 let data = get(url);
102
103 serde_json::from_slice(&data.await.unwrap()).unwrap()
104}
diff --git a/src/db.rs b/src/db.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/db.rs
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 @@
1pub mod update;
2pub mod apis;
3
4pub 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 @@
1use modlist::modrinth::projects;
2
3#[tokio::main]
4async fn main() {
5 //projects(vec!["kYuIpRLv", "89Wsn8GD"]);
6 println!("{:?}", projects(vec!["kYuIpRLv", "89Wsn8GD"]).await);
7}
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 @@
1pub fn update_mods() {
2
3}
4
5fn get_version(link: String) {
6
7
8}