summaryrefslogtreecommitdiff
path: root/src/apis/modrinth.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-05-29 18:02:08 +0200
committerfx <[email protected]>2023-05-29 18:02:08 +0200
commitd3870a2efa74e68c643dfb4aef32edc2536503b0 (patch)
tree116075aaa57c35afca2749719d450c3cb473ab3e /src/apis/modrinth.rs
parent5a2ea0755b29a8811aeeec1c73679c5783082628 (diff)
parentc7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 (diff)
downloadmodlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.tar
modlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.tar.gz
modlist-d3870a2efa74e68c643dfb4aef32edc2536503b0.zip
Merge pull request 'multithreaded' (#6) from multithreaded into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/6
Diffstat (limited to 'src/apis/modrinth.rs')
-rw-r--r--src/apis/modrinth.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index 525cc0d..9a22633 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -127,10 +127,13 @@ pub enum GameVersionType {
127 release, 127 release,
128 snapshot, 128 snapshot,
129 alpha, 129 alpha,
130 beta 130 beta,
131} 131}
132 132
133async fn get(api: &str, path: &str) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> { 133async fn get(
134 api: &str,
135 path: &str,
136) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> {
134 let url = format!(r#"{}{}"#, api, path); 137 let url = format!(r#"{}{}"#, api, path);
135 138
136 let client = Client::builder() 139 let client = Client::builder()
@@ -170,7 +173,7 @@ pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> {
170pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { 173pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> {
171 let url = format!( 174 let url = format!(
172 r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, 175 r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#,
173 id, list.modloader.to_string(), list.mc_version 176 id, list.modloader, list.mc_version
174 ); 177 );
175 178
176 let data = get(api, &url).await.unwrap(); 179 let data = get(api, &url).await.unwrap();
@@ -182,7 +185,10 @@ pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> {
182} 185}
183 186
184///Get version with the version ids 187///Get version with the version ids
185pub async fn get_raw_versions(api: &str, versions: Vec<String>) -> Vec<Version> { 188pub async fn get_raw_versions(
189 api: &str,
190 versions: Vec<String>,
191) -> Vec<Version> {
186 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); 192 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#));
187 193
188 let data = get(api, &url).await.unwrap().unwrap(); 194 let data = get(api, &url).await.unwrap().unwrap();
@@ -208,7 +214,10 @@ pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> {
208} 214}
209 215
210pub async fn get_game_versions() -> Vec<GameVersion> { 216pub async fn get_game_versions() -> Vec<GameVersion> {
211 let data = get("https://api.modrinth.com/v2/", "tag/game_version").await.unwrap().unwrap(); 217 let data = get("https://api.modrinth.com/v2/", "tag/game_version")
218 .await
219 .unwrap()
220 .unwrap();
212 221
213 serde_json::from_slice(&data).unwrap() 222 serde_json::from_slice(&data).unwrap()
214} 223}