feat(content): add datapack discovery and world installs

This commit is contained in:
objz committed 2026-08-01 19:47:47 +02:00
1 parent a98426e22a
commit 7986bab3a7
27 files changed
+1138 -119

No files matched your search

+13
View File
@@ -15,6 +15,7 @@ const MINECRAFT_GAME_ID: u32 = 432;
const MODS_CLASS_ID: u32 = 6;
const RESOURCE_PACKS_CLASS_ID: u32 = 12;
const SHADERS_CLASS_ID: u32 = 6552;
const DATA_PACKS_CLASS_ID: u32 = 6945;
pub const MODPACKS_CLASS_ID: u32 = 4471;
#[derive(Debug, Deserialize)]
@@ -34,6 +35,8 @@ struct Pagination {
#[serde(rename_all = "camelCase")]
struct Mod {
id: u64,
#[serde(default)]
class_id: u32,
name: String,
slug: String,
#[serde(default)]
@@ -314,6 +317,15 @@ fn project_info(project: Mod, body: String) -> ProjectInfo {
})
.collect(),
additional_categories: Vec::new(),
project_type: match project.class_id {
MODS_CLASS_ID => "mod",
RESOURCE_PACKS_CLASS_ID => "resourcepack",
SHADERS_CLASS_ID => "shader",
DATA_PACKS_CLASS_ID => "datapack",
_ => "",
}
.to_owned(),
loaders: Vec::new(),
}
}
@@ -501,6 +513,7 @@ fn class_id(kind: ContentKind) -> u32 {
ContentKind::Mod => MODS_CLASS_ID,
ContentKind::ResourcePack => RESOURCE_PACKS_CLASS_ID,
ContentKind::Shader => SHADERS_CLASS_ID,
ContentKind::DataPack => DATA_PACKS_CLASS_ID,
}
}
+18 -1
View File
@@ -18,6 +18,10 @@ pub struct ProjectInfo {
pub categories: Vec<String>,
#[serde(default)]
pub additional_categories: Vec<String>,
#[serde(default)]
pub project_type: String,
#[serde(default)]
pub loaders: Vec<String>,
}
impl ProjectInfo {
@@ -229,7 +233,7 @@ pub async fn search_modpacks(
}
fn discovery_facets(kind: ContentKind, game_version: &str, loader: ModLoader) -> String {
let mut facets = vec![vec![format!("project_type:{}", project_type(kind))]];
let mut facets = vec![vec![project_type_facet(kind)]];
if !game_version.is_empty() {
facets.push(vec![format!("versions:{game_version}")]);
}
@@ -241,11 +245,19 @@ fn discovery_facets(kind: ContentKind, game_version: &str, loader: ModLoader) ->
serde_json::to_string(&facets).unwrap_or_else(|_| "[]".to_string())
}
fn project_type_facet(kind: ContentKind) -> String {
match kind {
ContentKind::DataPack => "all_project_types:datapack".to_owned(),
_ => format!("project_type:{}", project_type(kind)),
}
}
fn project_type(kind: ContentKind) -> &'static str {
match kind {
ContentKind::Mod => "mod",
ContentKind::ResourcePack => "resourcepack",
ContentKind::Shader => "shader",
ContentKind::DataPack => "datapack",
}
}
@@ -361,6 +373,11 @@ fn content_versions_url(
"loaders={}",
url_encode(&serde_json::to_string(&[loader]).unwrap_or_default())
));
} else if kind == ContentKind::DataPack {
params.push(format!(
"loaders={}",
url_encode(&serde_json::to_string(&["datapack"]).unwrap_or_default())
));
}
format!(
"{api_base}/project/{}/version?{}",
+5
View File
@@ -58,6 +58,11 @@ fn curseforge_library_category_maps_to_cleanup_metadata() {
assert!(project_info(project, String::new()).is_library_only());
}
#[test]
fn datapack_discovery_uses_the_curseforge_data_packs_class() {
assert_eq!(class_id(ContentKind::DataPack), 6945);
}
#[tokio::test]
async fn curseforge_versions_follow_pagination() {
use wiremock::matchers::{method, path, query_param};
+26
View File
@@ -61,6 +61,8 @@ fn only_exclusively_library_categorized_projects_are_cleanup_eligible() {
.map(|category| (*category).to_owned())
.collect(),
additional_categories: Vec::new(),
project_type: "mod".to_owned(),
loaders: Vec::new(),
};
assert!(project(&["library"]).is_library_only());
@@ -91,6 +93,15 @@ fn discovery_resource_pack_facets_do_not_require_loader() {
);
}
#[test]
fn discovery_datapack_facets_use_the_datapack_project_type() {
let facets = discovery_facets(ContentKind::DataPack, "1.21.1", ModLoader::Fabric);
assert_eq!(
serde_json::from_str::<Vec<Vec<String>>>(&facets).unwrap(),
vec![vec!["all_project_types:datapack"], vec!["versions:1.21.1"]]
);
}
#[test]
fn compatible_mod_versions_filter_by_game_and_loader() {
let url = content_versions_url(
@@ -121,6 +132,21 @@ fn compatible_resource_pack_versions_do_not_filter_by_loader() {
);
}
#[test]
fn compatible_datapack_versions_filter_by_datapack_loader() {
let url = content_versions_url(
"https://example.test/v2",
"terralith",
ContentKind::DataPack,
"1.21.1",
ModLoader::Fabric,
);
assert_eq!(
url,
"https://example.test/v2/project/terralith/version?include_changelog=false&game_versions=%5B%221.21.1%22%5D&loaders=%5B%22datapack%22%5D"
);
}
#[test]
fn primary_file_selection_falls_back_to_first_file() {
let version = version_with_files(vec![