diff options
author | fxqnlr <[email protected]> | 2022-11-03 21:34:04 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-03 21:34:04 +0100 |
commit | 96cc5257de09682df345e768dc2a91303f9b36c9 (patch) | |
tree | f505d14c581e2bef4cfe222bd1069661bedd22e0 /src/apis | |
parent | b125dfd03084fff47ab8e90d002c6699b762d998 (diff) | |
download | modlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar modlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar.gz modlist-96cc5257de09682df345e768dc2a91303f9b36c9.zip |
added update beginnings; init of tests
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 3af5bbd..0c3eca5 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use serde::Deserialize; | 1 | use serde::Deserialize; |
2 | 2 | ||
3 | use crate::Modloader; | 3 | use crate::{Modloader, List}; |
4 | 4 | ||
5 | #[derive(Debug, Deserialize)] | 5 | #[derive(Debug, Deserialize)] |
6 | pub struct Project { | 6 | pub struct Project { |
@@ -68,7 +68,7 @@ pub enum Status { | |||
68 | unknown | 68 | unknown |
69 | } | 69 | } |
70 | 70 | ||
71 | #[derive(Debug, Deserialize)] | 71 | #[derive(Debug, Clone, Deserialize)] |
72 | pub struct Version { | 72 | pub struct Version { |
73 | pub name: String, | 73 | pub name: String, |
74 | pub version_number: String, | 74 | pub version_number: String, |
@@ -86,14 +86,14 @@ pub struct Version { | |||
86 | } | 86 | } |
87 | 87 | ||
88 | #[allow(non_camel_case_types)] | 88 | #[allow(non_camel_case_types)] |
89 | #[derive(Debug, Deserialize)] | 89 | #[derive(Debug, Clone, Deserialize)] |
90 | pub enum VersionType { | 90 | pub enum VersionType { |
91 | release, | 91 | release, |
92 | beta, | 92 | beta, |
93 | alpha | 93 | alpha |
94 | } | 94 | } |
95 | 95 | ||
96 | #[derive(Debug, Deserialize)] | 96 | #[derive(Debug, Clone, Deserialize)] |
97 | pub struct VersionFile { | 97 | pub struct VersionFile { |
98 | pub hashes: Hash, | 98 | pub hashes: Hash, |
99 | pub url: String, | 99 | pub url: String, |
@@ -102,7 +102,7 @@ pub struct VersionFile { | |||
102 | pub size: u32, | 102 | pub size: u32, |
103 | } | 103 | } |
104 | 104 | ||
105 | #[derive(Debug, Deserialize)] | 105 | #[derive(Debug, Clone, Deserialize)] |
106 | pub struct Hash { | 106 | pub struct Hash { |
107 | pub sha512: String, | 107 | pub sha512: String, |
108 | pub sha1: String, | 108 | pub sha1: String, |
@@ -130,7 +130,7 @@ pub async fn project(api: String, name: &str) -> Project { | |||
130 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 130 | serde_json::from_slice(&data.await.unwrap()).unwrap() |
131 | } | 131 | } |
132 | 132 | ||
133 | pub async fn projects(api: String, ids: Vec<&str>) -> Vec<Project> { | 133 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { |
134 | let all = ids.join(r#"",""#); | 134 | let all = ids.join(r#"",""#); |
135 | let url = format!(r#"projects?ids=["{}"]"#, all); | 135 | let url = format!(r#"projects?ids=["{}"]"#, all); |
136 | println!("{}", url); | 136 | println!("{}", url); |
@@ -140,14 +140,14 @@ pub async fn projects(api: String, ids: Vec<&str>) -> Vec<Project> { | |||
140 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 140 | serde_json::from_slice(&data.await.unwrap()).unwrap() |
141 | } | 141 | } |
142 | 142 | ||
143 | pub async fn versions(api: String, id: String, loader: Modloader, mc_version: String) -> Vec<Version> { | 143 | pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { |
144 | 144 | ||
145 | let loaderstr = match loader { | 145 | let loaderstr = match list.modloader { |
146 | Modloader::Forge => String::from("forge"), | 146 | Modloader::Forge => String::from("forge"), |
147 | Modloader::Fabric => String::from("fabric"), | 147 | Modloader::Fabric => String::from("fabric"), |
148 | }; | 148 | }; |
149 | 149 | ||
150 | let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, mc_version); | 150 | let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, list.mc_version); |
151 | 151 | ||
152 | let data = get(api, url); | 152 | let data = get(api, url); |
153 | 153 | ||