fix(content): only clean up library dependencies
This commit is contained in:
1 parent
8f920080d1
commit
aefc4535e1
14 files changed
+209
-14
No files matched your search
+32
-8
@@ -41,6 +41,14 @@ struct Mod {
|
||||
#[serde(default)]
|
||||
download_count: u64,
|
||||
logo: Option<Logo>,
|
||||
#[serde(default)]
|
||||
categories: Vec<Category>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Category {
|
||||
name: String,
|
||||
slug: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -283,14 +291,30 @@ pub async fn fetch_project(
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
Ok(ProjectInfo {
|
||||
id: project.data.id.to_string(),
|
||||
slug: project.data.slug,
|
||||
title: project.data.name,
|
||||
description: project.data.summary,
|
||||
body: description.data,
|
||||
icon_url: project.data.logo.map(|logo| logo.thumbnail_url),
|
||||
})
|
||||
Ok(project_info(project.data, description.data))
|
||||
}
|
||||
|
||||
fn project_info(project: Mod, body: String) -> ProjectInfo {
|
||||
ProjectInfo {
|
||||
id: project.id.to_string(),
|
||||
slug: project.slug,
|
||||
title: project.name,
|
||||
description: project.summary,
|
||||
body,
|
||||
icon_url: project.logo.map(|logo| logo.thumbnail_url),
|
||||
categories: project
|
||||
.categories
|
||||
.into_iter()
|
||||
.map(|category| {
|
||||
if category.slug.is_empty() {
|
||||
category.name
|
||||
} else {
|
||||
category.slug
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
additional_categories: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn fetch_versions(
|
||||
|
||||
@@ -14,6 +14,32 @@ pub struct ProjectInfo {
|
||||
pub body: String,
|
||||
#[serde(default)]
|
||||
pub icon_url: Option<String>,
|
||||
#[serde(default)]
|
||||
pub categories: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub additional_categories: Vec<String>,
|
||||
}
|
||||
|
||||
impl ProjectInfo {
|
||||
pub fn is_library_only(&self) -> bool {
|
||||
let mut categories = self
|
||||
.categories
|
||||
.iter()
|
||||
.chain(self.additional_categories.iter())
|
||||
.peekable();
|
||||
categories.peek().is_some()
|
||||
&& categories.all(|category| {
|
||||
matches!(
|
||||
category
|
||||
.chars()
|
||||
.filter(|character| character.is_alphanumeric())
|
||||
.flat_map(char::to_lowercase)
|
||||
.collect::<String>()
|
||||
.as_str(),
|
||||
"library" | "libraries" | "apiandlibrary" | "libraryapi"
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, serde::Serialize)]
|
||||
|
||||
@@ -40,6 +40,24 @@ fn curseforge_file_maps_to_shared_version() {
|
||||
assert_eq!(version.files[0].hashes["sha1"], "abc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curseforge_library_category_maps_to_cleanup_metadata() {
|
||||
let project: Mod = serde_json::from_str(
|
||||
r#"{
|
||||
"id": 7,
|
||||
"name": "Library",
|
||||
"slug": "library",
|
||||
"categories": [{
|
||||
"name": "API and Library",
|
||||
"slug": "library-api"
|
||||
}]
|
||||
}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(project_info(project, String::new()).is_library_only());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn curseforge_versions_follow_pagination() {
|
||||
use wiremock::matchers::{method, path, query_param};
|
||||
|
||||
@@ -47,6 +47,28 @@ fn version_dependencies_and_release_type_are_deserialized() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_exclusively_library_categorized_projects_are_cleanup_eligible() {
|
||||
let project = |categories: &[&str]| ProjectInfo {
|
||||
id: "project".to_owned(),
|
||||
slug: "project".to_owned(),
|
||||
title: "Project".to_owned(),
|
||||
description: String::new(),
|
||||
body: String::new(),
|
||||
icon_url: None,
|
||||
categories: categories
|
||||
.iter()
|
||||
.map(|category| (*category).to_owned())
|
||||
.collect(),
|
||||
additional_categories: Vec::new(),
|
||||
};
|
||||
|
||||
assert!(project(&["library"]).is_library_only());
|
||||
assert!(project(&["api-and-library"]).is_library_only());
|
||||
assert!(!project(&[]).is_library_only());
|
||||
assert!(!project(&["library", "utility"]).is_library_only());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_mod_facets_include_instance_compatibility() {
|
||||
let facets = discovery_facets(ContentKind::Mod, "1.21.1", ModLoader::Fabric);
|
||||
|
||||
Reference in new issue
Block a user