Enhance app version management and improve plugin list filtering with advanced search capabilities
This commit is contained in:
1 parent
61becf8d22
commit
0240ab9c50
19 files changed
+1771
-176
No files matched your search
@@ -7,6 +7,7 @@ use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
use crate::models::repository::RepositoryPlugin;
|
||||
use crate::crawlers::Repository;
|
||||
use regex;
|
||||
|
||||
// GitHub API response structures (Based on https://docs.github.com/en/rest/releases/releases)
|
||||
|
||||
@@ -112,6 +113,82 @@ impl GitHubCrawler {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to extract Minecraft versions from text
|
||||
fn extract_minecraft_versions(body: Option<&str>, description: &str) -> Vec<String> {
|
||||
let mut versions = Vec::new();
|
||||
|
||||
// Common version patterns
|
||||
let version_pattern = regex::Regex::new(r"(?i)(1\.\d{1,2}(?:\.\d{1,2})?)").unwrap();
|
||||
|
||||
// Check release body
|
||||
if let Some(text) = body {
|
||||
for cap in version_pattern.captures_iter(text) {
|
||||
if let Some(version) = cap.get(1) {
|
||||
versions.push(version.as_str().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check description if we didn't find any versions
|
||||
if versions.is_empty() {
|
||||
for cap in version_pattern.captures_iter(description) {
|
||||
if let Some(version) = cap.get(1) {
|
||||
versions.push(version.as_str().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If still empty, add a default
|
||||
if versions.is_empty() {
|
||||
versions.push("Unknown".to_string());
|
||||
}
|
||||
|
||||
versions
|
||||
}
|
||||
|
||||
// Helper function to extract supported loaders from text
|
||||
fn extract_loaders(body: Option<&str>, description: &str) -> Vec<String> {
|
||||
let mut loaders = Vec::new();
|
||||
|
||||
// Check for common loader keywords
|
||||
let mut check_for_loader = |text: &str, loader_name: &str| {
|
||||
if text.to_lowercase().contains(&loader_name.to_lowercase()) {
|
||||
loaders.push(loader_name.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
// Process both body and description
|
||||
let empty_string = String::new();
|
||||
let body_str = body.unwrap_or("");
|
||||
|
||||
check_for_loader(body_str, "Paper");
|
||||
check_for_loader(body_str, "Spigot");
|
||||
check_for_loader(body_str, "Bukkit");
|
||||
check_for_loader(body_str, "Forge");
|
||||
check_for_loader(body_str, "Fabric");
|
||||
check_for_loader(body_str, "Velocity");
|
||||
check_for_loader(body_str, "BungeeCord");
|
||||
check_for_loader(body_str, "Waterfall");
|
||||
|
||||
check_for_loader(description, "Paper");
|
||||
check_for_loader(description, "Spigot");
|
||||
check_for_loader(description, "Bukkit");
|
||||
check_for_loader(description, "Forge");
|
||||
check_for_loader(description, "Fabric");
|
||||
check_for_loader(description, "Velocity");
|
||||
check_for_loader(description, "BungeeCord");
|
||||
check_for_loader(description, "Waterfall");
|
||||
|
||||
// If no loaders detected, assume Bukkit/Spigot/Paper as most common
|
||||
if loaders.is_empty() {
|
||||
loaders.push("Bukkit".to_string());
|
||||
loaders.push("Spigot".to_string());
|
||||
loaders.push("Paper".to_string());
|
||||
}
|
||||
|
||||
loaders
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Repository for GitHubCrawler {
|
||||
fn get_repository_name(&self) -> String {
|
||||
@@ -180,7 +257,7 @@ impl Repository for GitHubCrawler {
|
||||
id: repo_full_name.to_string(),
|
||||
name: repo.name,
|
||||
version: release.tag_name,
|
||||
description: repo.description,
|
||||
description: repo.description.clone(),
|
||||
authors: vec![repo.owner.login],
|
||||
download_url: asset.browser_download_url.clone(),
|
||||
repository: RepositorySource::GitHub,
|
||||
@@ -188,12 +265,23 @@ impl Repository for GitHubCrawler {
|
||||
download_count: Some(asset.download_count),
|
||||
last_updated: Some(release.published_at),
|
||||
icon_url: repo.owner.avatar_url,
|
||||
minecraft_versions: Vec::new(),
|
||||
minecraft_versions: extract_minecraft_versions(
|
||||
release.body.as_deref(),
|
||||
&repo.description.clone().unwrap_or_default()
|
||||
),
|
||||
categories: Vec::new(),
|
||||
rating: Some(repo.stargazers_count as f32),
|
||||
file_size: Some(asset.size),
|
||||
file_hash: None,
|
||||
changelog: release.body,
|
||||
changelog: release.body.clone(),
|
||||
loaders: extract_loaders(
|
||||
release.body.as_deref(),
|
||||
&repo.description.clone().unwrap_or_default()
|
||||
),
|
||||
supported_versions: extract_minecraft_versions(
|
||||
release.body.as_deref(),
|
||||
&repo.description.clone().unwrap_or_default()
|
||||
),
|
||||
})
|
||||
} else {
|
||||
Err(format!("No suitable JAR asset found in the latest valid release for {}", repo_full_name))
|
||||
|
||||
@@ -34,6 +34,9 @@ struct HangarProject {
|
||||
icon_url: Option<String>,
|
||||
created_at: String,
|
||||
visibility: String,
|
||||
game_versions: Vec<String>,
|
||||
platform: String,
|
||||
categories: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -138,12 +141,14 @@ impl Repository for HangarCrawler {
|
||||
download_count: Some(proj.stats.downloads),
|
||||
last_updated: Some(proj.last_updated),
|
||||
icon_url: proj.icon_url.clone(),
|
||||
minecraft_versions: Vec::new(),
|
||||
categories: vec![proj.category.to_string()],
|
||||
minecraft_versions: proj.game_versions.clone(),
|
||||
categories: proj.categories.clone(),
|
||||
rating: Some(proj.stats.stars as f32),
|
||||
file_size: None,
|
||||
file_hash: None,
|
||||
changelog: None,
|
||||
loaders: vec![proj.platform.clone()],
|
||||
supported_versions: proj.game_versions.clone(),
|
||||
}
|
||||
}).collect();
|
||||
|
||||
@@ -184,12 +189,14 @@ impl Repository for HangarCrawler {
|
||||
download_count: Some(project.stats.downloads),
|
||||
last_updated: Some(project.last_updated),
|
||||
icon_url: project.icon_url.clone(),
|
||||
minecraft_versions: versions.first().map_or(Vec::new(), |v| v.platform_versions.clone()),
|
||||
categories: vec![project.category.to_string()],
|
||||
minecraft_versions: project.game_versions.clone(),
|
||||
categories: project.categories.clone(),
|
||||
rating: Some(project.stats.stars as f32),
|
||||
file_size: versions.first().map(|v| v.file_size),
|
||||
file_hash: None,
|
||||
changelog: None,
|
||||
loaders: vec![project.platform.clone()],
|
||||
supported_versions: project.game_versions.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,8 @@ impl ModrinthCrawler {
|
||||
file_size: primary_file.map(|f| f.size),
|
||||
file_hash: primary_file.map(|f| f.hashes.sha512.clone()), // Use SHA512
|
||||
changelog,
|
||||
loaders: latest_version_opt.map_or(Vec::new(), |v| v.loaders.clone()),
|
||||
supported_versions: latest_version_opt.map_or(project.game_versions.clone(), |v| v.game_versions.clone()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -334,6 +336,8 @@ impl Repository for ModrinthCrawler {
|
||||
file_size: None,
|
||||
file_hash: None,
|
||||
changelog: None,
|
||||
loaders: Vec::new(),
|
||||
supported_versions: Vec::new(),
|
||||
};
|
||||
results.push(repo_plugin);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,8 @@ impl SpigotMCCrawler {
|
||||
file_size: file_size_bytes,
|
||||
file_hash: None, // SpiGet does not provide hashes
|
||||
changelog: None, // Needs separate call to /updates/latest
|
||||
loaders: vec!["Spigot".to_string(), "Paper".to_string()], // SpigotMC resources typically work on Spigot and Paper
|
||||
supported_versions: resource.tested_versions.clone(), // Same as minecraft_versions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user