1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
use serde::{Deserialize, Serialize};
async fn get(path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
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<String>,
pub client_side: Side,
pub server_side: Side,
pub body: String,
pub additional_categories: Option<Vec<String>>,
pub project_type: Type,
pub downloads: u32,
pub icon_url: Option<String>,
pub id: String,
pub team: String,
pub moderator_message: Option<ModeratorMessage>,
pub published: String,
pub updated: String,
pub approved: Option<String>,
pub followers: u32,
pub status: Status,
pub license: License,
pub versions: Vec<String>,
}
#[derive(Debug, Deserialize)]
pub struct License {
pub id: String,
pub name: String,
pub url: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct ModeratorMessage {
pub message: String,
pub body: Option<String>,
}
#[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<Project> {
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()
}
|