Store metadata on whether the mod is needed on client and server sides

This commit is contained in:
Warren Hood 2024-08-18 23:54:53 +02:00
parent 08e8bf4ede
commit 21b5e443bf
2 changed files with 15 additions and 5 deletions

View file

@ -18,5 +18,9 @@ pub struct PinnedMod {
/// Version of mod /// Version of mod
pub version: String, pub version: String,
/// Pinned dependencies of a pinned mod /// Pinned dependencies of a pinned mod
pub deps: Option<HashSet<ModMeta>> pub deps: Option<HashSet<ModMeta>>,
/// Server side
pub server_side: bool,
/// Required on client side
pub client_side: bool
} }

View file

@ -15,6 +15,8 @@ pub struct Modrinth {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct ModrinthProject { struct ModrinthProject {
slug: String, slug: String,
client_side: String,
server_side: String
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -63,8 +65,8 @@ impl Modrinth {
} }
} }
pub async fn get_project_slug(&self, project_id: &str) -> Result<String, Box<dyn Error>> { pub async fn get_project(&self, project_id: &str) -> Result<ModrinthProject, Box<dyn Error>> {
let mut project: ModrinthProject = self let project: ModrinthProject = self
.client .client
.get(format!("https://api.modrinth.com/v2/project/{project_id}")) .get(format!("https://api.modrinth.com/v2/project/{project_id}"))
.send() .send()
@ -72,7 +74,7 @@ impl Modrinth {
.json() .json()
.await?; .await?;
Ok(project.slug) Ok(project)
} }
pub async fn get_mod_meta( pub async fn get_mod_meta(
@ -92,7 +94,7 @@ impl Modrinth {
game_version_override, game_version_override,
) )
.await?; .await?;
let project_slug = self.get_project_slug(project_id).await?; let project_slug = self.get_project(project_id).await?.slug;
for version in project_versions.iter() { for version in project_versions.iter() {
if project_version.is_none() || project_version.unwrap_or("*") == version.id { if project_version.is_none() || project_version.unwrap_or("*") == version.id {
@ -159,6 +161,8 @@ impl Modrinth {
} }
} }
let project = self.get_project(&mod_meta.name).await?;
Ok(PinnedMod { Ok(PinnedMod {
source: package source: package
.files .files
@ -180,6 +184,8 @@ impl Modrinth {
} else { } else {
None None
}, },
server_side: project.server_side != "optional",
client_side: project.client_side != "optional"
}) })
} }