summaryrefslogtreecommitdiff
path: root/src/apis/modrinth.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-17 21:20:09 +0100
committerfxqnlr <[email protected]>2022-11-17 21:20:09 +0100
commitfdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 (patch)
treeec7c7c80434b339f9442882f1e2dce6f60cc9edd /src/apis/modrinth.rs
parent5145dd23f1777180d8003e76f59af57643796516 (diff)
downloadmodlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar
modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar.gz
modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.zip
added --clean for update && list downloadfolder
Diffstat (limited to 'src/apis/modrinth.rs')
-rw-r--r--src/apis/modrinth.rs9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index abb8eec..ec8d203 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -124,7 +124,6 @@ async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::E
124 Ok(data) 124 Ok(data)
125} 125}
126 126
127
128pub async fn project(api: String, name: &str) -> Project { 127pub async fn project(api: String, name: &str) -> Project {
129 let url = format!("project/{}", name); 128 let url = format!("project/{}", name);
130 let data = get(api, url); 129 let data = get(api, url);
@@ -143,7 +142,6 @@ pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> {
143} 142}
144 143
145pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { 144pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
146
147 let loaderstr = match list.modloader { 145 let loaderstr = match list.modloader {
148 Modloader::Forge => String::from("forge"), 146 Modloader::Forge => String::from("forge"),
149 Modloader::Fabric => String::from("fabric"), 147 Modloader::Fabric => String::from("fabric"),
@@ -157,7 +155,7 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
157} 155}
158 156
159pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { 157pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> {
160 println!("Getting versions"); 158 println!("Getting versions {}", &versions.join(", "));
161 159
162 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); 160 let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#));
163 161
@@ -169,18 +167,15 @@ pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version
169pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { 167pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> {
170 match versions.len() { 168 match versions.len() {
171 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), 169 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))),
172 //TODO compare publish dates
173 1.. => { 170 1.. => {
174 let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; 171 let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![];
175 for ver in versions { 172 for ver in versions {
176 let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?; 173 let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?;
177 times.push((ver.id, stamp)) 174 times.push((ver.id, stamp))
178 } 175 }
179 dbg!(&times);
180 times.sort_by_key(|t| t.1); 176 times.sort_by_key(|t| t.1);
181 times.reverse(); 177 times.reverse();
182 dbg!(&times); 178 println!("Current Version: {}", times[0].0);
183 println!("CW: {}", times[0].0);
184 Ok(times[0].0.to_string()) 179 Ok(times[0].0.to_string())
185 }, 180 },
186 _ => panic!("available_versions should never be negative"), 181 _ => panic!("available_versions should never be negative"),