diff --git a/src/model/servertoml.rs b/src/model/servertoml.rs index 46d28a8..af957fa 100644 --- a/src/model/servertoml.rs +++ b/src/model/servertoml.rs @@ -9,9 +9,7 @@ use std::{ use anyhow::{anyhow, bail, Result}; use serde::{Deserialize, Serialize}; -use crate::sources::modrinth; - -use super::{ClientSideMod, Downloadable, ServerLauncher, ServerType, SoftwareType, World}; +use super::{ClientSideMod, Downloadable, ServerLauncher, ServerType, World}; #[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)] #[serde(default)] @@ -97,7 +95,6 @@ impl Server { Ok(()) } - #[allow(dead_code)] pub fn format(&self, str: &str) -> String { mcapi::dollar_repl(str, |key| match key { "mcver" | "mcversion" | "SERVER_VERSION" => Some(self.mc_version.clone()), @@ -151,34 +148,6 @@ impl Server { map } - - // TODO: move to ModrinthAPI - pub fn filter_modrinth_versions( - &self, - list: &[modrinth::ModrinthVersion], - ) -> Vec { - let is_proxy = self.jar.get_software_type() == SoftwareType::Proxy; - let is_vanilla = matches!(self.jar, ServerType::Vanilla {}); - - let mcver = &self.mc_version; - let loader = self.jar.get_modrinth_name(); - - list.iter() - .filter(|v| is_proxy || v.game_versions.contains(mcver)) - .filter(|v| { - if let Some(n) = &loader { - v.loaders - .iter() - .any(|l| l == "datapack" || l == n || (l == "fabric" && n == "quilt")) - } else if is_vanilla { - v.loaders.contains(&"datapack".to_owned()) - } else { - true - } - }) - .cloned() - .collect() - } } impl Default for Server { diff --git a/src/sources/modrinth.rs b/src/sources/modrinth.rs index 2e0c5cf..89a8b76 100644 --- a/src/sources/modrinth.rs +++ b/src/sources/modrinth.rs @@ -7,7 +7,7 @@ use tokio::time::sleep; use crate::{ app::{App, CacheStrategy, ResolvedFile}, - model::SoftwareType, + model::{SoftwareType, ServerType}, }; #[derive(Debug, Deserialize, Serialize, Clone)] @@ -162,12 +162,12 @@ impl<'a> ModrinthAPI<'a> { pub async fn fetch_versions(&self, id: &str) -> Result> { let versions = self.fetch_all_versions(id).await?; - Ok(self.0.server.filter_modrinth_versions(&versions)) + Ok(self.filter_versions(&versions)) } pub async fn fetch_version(&self, id: &str, version: &str) -> Result { let all_versions = self.fetch_all_versions(id).await?; - let versions = self.0.server.filter_modrinth_versions(&all_versions); + let versions = self.filter_versions(&all_versions); let ver = version.replace("${mcver}", &self.0.mc_version()); let ver = ver.replace("${mcversion}", &self.0.mc_version()); @@ -243,6 +243,33 @@ impl<'a> ModrinthAPI<'a> { serde_json::to_string(&arr).unwrap() } + pub fn filter_versions( + &self, + list: &[ModrinthVersion], + ) -> Vec { + let is_proxy = self.0.server.jar.get_software_type() == SoftwareType::Proxy; + let is_vanilla = matches!(self.0.server.jar, ServerType::Vanilla {}); + + let mcver = &self.0.mc_version(); + let loader = self.0.server.jar.get_modrinth_name(); + + list.iter() + .filter(|v| is_proxy || v.game_versions.contains(mcver)) + .filter(|v| { + if let Some(n) = &loader { + v.loaders + .iter() + .any(|l| l == "datapack" || l == n || (l == "fabric" && n == "quilt")) + } else if is_vanilla { + v.loaders.contains(&"datapack".to_owned()) + } else { + true + } + }) + .cloned() + .collect() + } + pub async fn search(&self, query: &str) -> Result> { Ok(self .0