summaryrefslogtreecommitdiff
path: root/src/apis/modrinth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/apis/modrinth.rs')
-rw-r--r--src/apis/modrinth.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index f3f89a7..bb5ee19 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -108,7 +108,7 @@ pub struct Hash {
108 pub sha1: String, 108 pub sha1: String,
109} 109}
110 110
111async fn get(api: String, path: String) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> { 111async fn get(api: &str, path: String) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> {
112 let url = format!(r#"{}{}"#, api, path); 112 let url = format!(r#"{}{}"#, api, path);
113 113
114 let client = Client::builder() 114 let client = Client::builder()
@@ -131,14 +131,14 @@ async fn get(api: String, path: String) -> Result<Option<Vec<u8>>, Box<dyn std::
131 Ok(data) 131 Ok(data)
132} 132}
133 133
134pub async fn project(api: String, name: &str) -> Project { 134pub async fn project(api: &str, name: &str) -> Project {
135 let url = format!("project/{}", name); 135 let url = format!("project/{}", name);
136 let data = get(api, url).await.unwrap().unwrap(); 136 let data = get(api, url).await.unwrap().unwrap();
137 137
138 serde_json::from_slice(&data).unwrap() 138 serde_json::from_slice(&data).unwrap()
139} 139}
140 140
141pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { 141pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> {
142 let all = ids.join(r#"",""#); 142 let all = ids.join(r#"",""#);
143 let url = format!(r#"projects?ids=["{}"]"#, all); 143 let url = format!(r#"projects?ids=["{}"]"#, all);
144 144
@@ -147,7 +147,8 @@ pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> {
147 serde_json::from_slice(&data).unwrap() 147 serde_json::from_slice(&data).unwrap()
148} 148}
149 149
150pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { 150///Get applicable versions from mod_id with list context
151pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> {
151 let loaderstr = match list.modloader { 152 let loaderstr = match list.modloader {
152 Modloader::Forge => String::from("forge"), 153 Modloader::Forge => String::from("forge"),
153 Modloader::Fabric => String::from("fabric"), 154 Modloader::Fabric => String::from("fabric"),
@@ -163,9 +164,8 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
163 } 164 }
164} 165}
165 166
166pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { 167///Get version with the version ids
167 println!("Getting versions {}", &versions.join(", ")); 168pub async fn get_raw_versions(api: &str, versions: Vec<String>) -> Vec<Version> {
168
169 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); 169 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#));
170 170
171 let data = get(api, url).await.unwrap().unwrap(); 171 let data = get(api, url).await.unwrap().unwrap();
@@ -204,7 +204,7 @@ pub struct MCVersion {
204 pub major: bool, 204 pub major: bool,
205} 205}
206 206
207pub async fn get_minecraft_version(api: String, version: MCVersionType) -> String { 207pub async fn get_minecraft_version(api: &str, version: MCVersionType) -> String {
208 let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap(); 208 let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap();
209 let mc_versions: Vec<MCVersion> = serde_json::from_slice(&data).unwrap(); 209 let mc_versions: Vec<MCVersion> = serde_json::from_slice(&data).unwrap();
210 let ver = match version { 210 let ver = match version {