summaryrefslogtreecommitdiff
path: root/src/apis
diff options
context:
space:
mode:
Diffstat (limited to 'src/apis')
-rw-r--r--src/apis/modrinth.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index c99cfbf..7b322cb 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -1,5 +1,6 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2use chrono::{DateTime, FixedOffset}; 2use chrono::{DateTime, FixedOffset};
3use reqwest::Client;
3use serde::Deserialize; 4use serde::Deserialize;
4 5
5use crate::{Modloader, List}; 6use crate::{Modloader, List};
@@ -113,18 +114,21 @@ pub struct Hash {
113async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> { 114async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
114 let url = format!(r#"{}{}"#, api, path); 115 let url = format!(r#"{}{}"#, api, path);
115 116
116 dbg!(&url); 117 let client = Client::builder()
117 118 .user_agent(format!("fxqnlr/modlistcli/{} ([email protected])", env!("CARGO_PKG_VERSION")))
118 let data = reqwest::get(url) 119 .build()?;
119 .await? 120 let data = client.get(url)
120 .bytes() 121 .send()
121 .await? 122 .await?
122 .to_vec(); 123 .bytes()
124 .await?
125 .to_vec();
123 126
124 Ok(data) 127 Ok(data)
125} 128}
126 129
127pub async fn project(api: String, name: &str) -> Project { 130pub async fn project(api: String, name: &str) -> Project {
131 println!("!!!PROJECT");
128 let url = format!("project/{}", name); 132 let url = format!("project/{}", name);
129 let data = get(api, url); 133 let data = get(api, url);
130 134
@@ -132,9 +136,11 @@ pub async fn project(api: String, name: &str) -> Project {
132} 136}
133 137
134pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { 138pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> {
139 //println!("!!!PROJECTS");
140 println!("Getting versions for all mods from modrinth");
135 let all = ids.join(r#"",""#); 141 let all = ids.join(r#"",""#);
136 let url = format!(r#"projects?ids=["{}"]"#, all); 142 let url = format!(r#"projects?ids=["{}"]"#, all);
137 println!("{}", url); 143 //println!("{}", url);
138 144
139 let data = get(api, url); 145 let data = get(api, url);
140 146
@@ -142,6 +148,7 @@ pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> {
142} 148}
143 149
144pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { 150pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
151 println!("!!!VERSIONS");
145 let loaderstr = match list.modloader { 152 let loaderstr = match list.modloader {
146 Modloader::Forge => String::from("forge"), 153 Modloader::Forge => String::from("forge"),
147 Modloader::Fabric => String::from("fabric"), 154 Modloader::Fabric => String::from("fabric"),
@@ -155,6 +162,7 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
155} 162}
156 163
157pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { 164pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> {
165 println!("!!!RAWVERSIONS");
158 println!("Getting versions {}", &versions.join(", ")); 166 println!("Getting versions {}", &versions.join(", "));
159 167
160 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); 168 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#));