diff options
author | FxQnLr <[email protected]> | 2022-11-29 22:59:19 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-11-29 22:59:19 +0100 |
commit | 575d2493e8e5747bf65321f7277e52211d73e387 (patch) | |
tree | 11b20e371316047110ffd36d1fe5bfefd2183c07 /src/apis | |
parent | ddde9204c72dd867f920f07f6483be03dda7cf68 (diff) | |
download | modlist-575d2493e8e5747bf65321f7277e52211d73e387.tar modlist-575d2493e8e5747bf65321f7277e52211d73e387.tar.gz modlist-575d2493e8e5747bf65321f7277e52211d73e387.zip |
fixed mod without matching specific version
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 7b322cb..fb1e666 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -111,18 +111,25 @@ pub struct Hash { | |||
111 | pub sha1: String, | 111 | pub sha1: String, |
112 | } | 112 | } |
113 | 113 | ||
114 | async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> { | 114 | async fn get(api: String, path: String) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> { |
115 | let url = format!(r#"{}{}"#, api, path); | 115 | let url = format!(r#"{}{}"#, api, path); |
116 | 116 | ||
117 | let client = Client::builder() | 117 | let client = Client::builder() |
118 | .user_agent(format!("fxqnlr/modlistcli/{} ([email protected])", env!("CARGO_PKG_VERSION"))) | 118 | .user_agent(format!("fxqnlr/modlistcli/{} ([email protected])", env!("CARGO_PKG_VERSION"))) |
119 | .build()?; | 119 | .build()?; |
120 | let data = client.get(url) | 120 | let res = client.get(url) |
121 | .send() | 121 | .send() |
122 | .await? | 122 | .await?; |
123 | .bytes() | 123 | |
124 | .await? | 124 | let mut data: Option<Vec<u8>> = None; |
125 | .to_vec(); | 125 | |
126 | if res.status() == 200 { | ||
127 | data = Some(res | ||
128 | .bytes() | ||
129 | .await? | ||
130 | .to_vec() | ||
131 | ); | ||
132 | } | ||
126 | 133 | ||
127 | Ok(data) | 134 | Ok(data) |
128 | } | 135 | } |
@@ -130,9 +137,9 @@ async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::E | |||
130 | pub async fn project(api: String, name: &str) -> Project { | 137 | pub async fn project(api: String, name: &str) -> Project { |
131 | println!("!!!PROJECT"); | 138 | println!("!!!PROJECT"); |
132 | let url = format!("project/{}", name); | 139 | let url = format!("project/{}", name); |
133 | let data = get(api, url); | 140 | let data = get(api, url).await.unwrap().unwrap(); |
134 | 141 | ||
135 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 142 | serde_json::from_slice(&data).unwrap() |
136 | } | 143 | } |
137 | 144 | ||
138 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { | 145 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { |
@@ -142,9 +149,9 @@ pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { | |||
142 | let url = format!(r#"projects?ids=["{}"]"#, all); | 149 | let url = format!(r#"projects?ids=["{}"]"#, all); |
143 | //println!("{}", url); | 150 | //println!("{}", url); |
144 | 151 | ||
145 | let data = get(api, url); | 152 | let data = get(api, url).await.unwrap().unwrap(); |
146 | 153 | ||
147 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 154 | serde_json::from_slice(&data).unwrap() |
148 | } | 155 | } |
149 | 156 | ||
150 | pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | 157 | pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { |
@@ -156,9 +163,14 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | |||
156 | 163 | ||
157 | let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, list.mc_version); | 164 | let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, list.mc_version); |
158 | 165 | ||
159 | let data = get(api, url); | 166 | let data = get(api, url).await.unwrap(); |
160 | 167 | ||
161 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 168 | dbg!(&data); |
169 | |||
170 | match data { | ||
171 | Some(data) => serde_json::from_slice(&data).unwrap(), | ||
172 | None => Vec::new(), | ||
173 | } | ||
162 | } | 174 | } |
163 | 175 | ||
164 | pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { | 176 | pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { |
@@ -167,9 +179,9 @@ pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version | |||
167 | 179 | ||
168 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); | 180 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); |
169 | 181 | ||
170 | let data = get(api, url).await; | 182 | let data = get(api, url).await.unwrap().unwrap(); |
171 | 183 | ||
172 | serde_json::from_slice(&data.unwrap()).unwrap() | 184 | serde_json::from_slice(&data).unwrap() |
173 | } | 185 | } |
174 | 186 | ||
175 | pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { | 187 | pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { |