diff --git a/src-tauri/src/crawlers/modrinth.rs b/src-tauri/src/crawlers/modrinth.rs index ee124da..cdb98c4 100644 --- a/src-tauri/src/crawlers/modrinth.rs +++ b/src-tauri/src/crawlers/modrinth.rs @@ -221,19 +221,44 @@ impl ModrinthCrawler { } pub async fn download_plugin_with_server_type(&self, plugin_id: &str, version_number_str: &str, destination: &Path, server_type: Option<&ServerType>) -> Result { + // First try to get compatible versions for the server type let versions = match self.get_compatible_versions(plugin_id, server_type).await { Ok(v) => v, Err(e) => return Err(format!("Failed to get Modrinth versions for download: {}", e)), }; - let target_version = versions.iter().find(|v| v.version_number == version_number_str); + // Try to find a version that matches the requested version number among compatible versions + let mut version_to_download = versions.into_iter().find(|v| v.version_number == version_number_str); - let version_to_download = match target_version { + // If no compatible version found, but we have a server type filter (meaning we actually filtered) + if version_to_download.is_none() && server_type.is_some() { + println!("No compatible version '{}' found for server type {:?}, attempting to find version without server compatibility check", + version_number_str, server_type); + + // Try to get all versions without server type filtering + match self.get_project_versions_internal(plugin_id).await { + Ok(all_versions) => { + // Look for the specific version number in all versions + version_to_download = all_versions.into_iter().find(|v| v.version_number == version_number_str); + + if version_to_download.is_some() { + println!("Found version '{}' without server compatibility check, proceeding with download", version_number_str); + } + }, + Err(e) => { + println!("Error getting all versions: {}", e); + // Continue with empty versions list, which will return an error below + } + } + } + + // If we still don't have a target version, return an error + let version = match version_to_download { Some(v) => v, None => return Err(format!("Version '{}' not found or not compatible for plugin {}", version_number_str, plugin_id)), }; - let primary_file = match version_to_download.files.iter().find(|f| f.primary) { + let primary_file = match version.files.iter().find(|f| f.primary) { Some(f) => f, None => return Err(format!("No primary file found for version '{}' of plugin {}", version_number_str, plugin_id)), };