Merge pull request #2173 from ludovic111/feat/mod-index-downloads

🤖 Agent: Merging. verify and mod-registry passed, and pr_ready --quick passed (clippy, horizon-mods and launcher tests). The index's downloads field is optional, so the schema doesn't change.
This commit is contained in:
Ludovic Marie
2026-10-26 15:02:11 +01:00
committed by GitHub
7 changed files with 40 additions and 8 deletions
+8
View File
@@ -122,6 +122,14 @@ pub struct Project {
pub key: Option<String>,
/// Newest first.
pub versions: Vec<Version>,
/// Its files' downloads from their releases, all versions together:
/// GitHub's counts, added by the registry's publish job (hourly).
#[serde(default, skip_serializing_if = "is_zero")]
pub downloads: u64,
}
fn is_zero(n: &u64) -> bool {
*n == 0
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -231,6 +231,7 @@ pub fn project(entry: &Entry, src: &Sources) -> Result<Project, Vec<String>> {
icon,
key: entry.key.as_ref().map(|k| k.trim().to_owned()),
versions,
downloads: 0,
})
}
+7 -1
View File
@@ -34,8 +34,14 @@ fn reads_the_sample_and_keeps_unknown_kinds() {
[Capability::GameRead, Capability::Hud, Capability::Chat]
);
// What CI writes reads back the same.
let again = Index::parse(&serde_json::to_string(&index).unwrap()).unwrap();
let text = serde_json::to_string(&index).unwrap();
let again = Index::parse(&text).unwrap();
assert_eq!(again, index);
// Download counts: the publish job adds them; none is left out.
assert_eq!(hud.downloads, 0);
assert!(!text.contains("downloads"));
let counted = text.replacen("\"versions\"", "\"downloads\":12345,\"versions\"", 1);
assert_eq!(Index::parse(&counted).unwrap().projects[0].downloads, 12345);
}
#[test]
+3 -1
View File
@@ -18,7 +18,7 @@ Level: preview ([stability.md](stability.md)). Schema 1.
"projects": [{
"id": "coords_hud", "kind": "mod", "name": "Coordinates HUD", "summary": "One line.",
"description": "Markdown.", "authors": ["Horizon"], "owners": ["ludovic111"],
"license": "MIT", "source": "https://github.com/...", "icon": "https://...png", "key": "RWT...",
"license": "MIT", "source": "https://github.com/...", "icon": "https://...png", "key": "RWT...", "downloads": 1234,
"versions": [{
"version": "0.1.0", "published": "2026-10-24", "changelog": "",
"api": "0.1", "side": "client", "capabilities": ["game-read", "hud", "chat"], "api_level": 0, "game": "26.3",
@@ -41,6 +41,7 @@ Level: preview ([stability.md](stability.md)). Schema 1.
| `icon` | `https://`, optional. |
| `key` | The author's [minisign](https://jedisct1.github.io/minisign/) public key. When set, every version must be signed with it; an update signed with another key is refused. Absent: the project is unsigned and the launcher says so. |
| `versions` | Newest first, at least one. |
| `downloads` | How many times its files were downloaded, every version together: GitHub's count of each release asset, summed by the publish job, which runs every hour. Absent until a file is downloaded. Read-only: never in an entry. |
| `api` | A mod's API line (its manifest's `api`); a modpack's manifest format (`1`). |
| `side`, `capabilities` | A mod's, read from its manifest by CI, never typed by hand. |
| `api_level` | The mod API level a mod's code needs ([stability.md](stability.md#mod-api-levels)): its newest imported function's, read from the file by CI. Absent for content-only mods and in indexes built before levels. Installers take the newest version whose level the running game serves. |
@@ -167,6 +168,7 @@ opens.
## Changelog
- 2026-10-26: `projects[].downloads`, GitHub's download counts of a project's files, refreshed every hour.
- 2026-10-26: the launcher installs `shader` files into `shaderpacks/`; the sample index lists one (`glow`).
- 2026-10-25: `shader` opens, checked by `horizon_shader_api::check`; its files are `.hshader`.
- Schema 1 (2026-10-24): kinds `mod`, `modpack`, `resourcepack`, `shader`; `.hpack` format 1.
+8 -3
View File
@@ -158,7 +158,7 @@ fn project_of(p: &index::Project) -> Option<Project> {
title: p.name.clone(),
summary: p.summary.clone(),
author: p.authors.join(", "),
downloads: 0,
downloads: p.downloads,
page: format!("{SITE}/{}", p.id),
icon: p.icon.clone(),
license: p.license.clone(),
@@ -218,14 +218,19 @@ fn matches(p: &index::Project, text: &str) -> bool {
.all(|word| hay.contains(&word.to_lowercase()))
}
/// The projects of the query's kind whose words match, for this game unless `everything`.
/// The projects of the query's kind whose words match, for this game unless `everything`: the
/// most downloaded first.
fn search(index: &Index, query: &Query) -> Vec<Project> {
index
let mut found: Vec<Project> = index
.projects
.iter()
.filter(|p| kind_of(&p.kind) == Some(query.kind) && matches(p, &query.text))
.filter(|p| query.everything || p.versions.iter().any(|v| v.game == GAME))
.filter_map(project_of)
.collect();
found.sort_by_key(|p| std::cmp::Reverse(p.downloads));
found
.into_iter()
.skip(query.offset)
.take(query.limit)
.collect()
+12
View File
@@ -49,6 +49,18 @@ fn searches_by_kind_and_words() {
assert_eq!(found("", Kind::Modpack), ["cozy"]);
assert!(found("skyblock", Kind::ResourcePack).is_empty());
assert_eq!(found("", Kind::Shader), ["glow"]);
// The index's download counts, most downloaded first.
let mut counted = index.clone();
counted.projects.push(index::Project {
id: "zoom".into(),
name: "Zoom".into(),
downloads: 12_345,
..index.project("coords_hud").unwrap().clone()
});
counted.projects[0].downloads = 80;
let first = search(&counted, &Query::new("", Kind::Mod));
let order: Vec<(&str, u64)> = first.iter().map(|p| (p.id.as_str(), p.downloads)).collect();
assert_eq!(order, [("zoom", 12_345), ("coords_hud", 80)]);
let p = hud(&index);
assert_eq!(p.support(), super::super::Support::Works);
assert_eq!(p.page, "https://playhorizon.dev/mods/coords_hud");
+1 -3
View File
@@ -968,9 +968,7 @@ impl Launcher {
if !p.author.is_empty() {
by.push(format!("by {}", p.author));
}
if p.source != SourceId::Horizon {
by.push(format!("{} downloads", count(p.downloads)));
}
by.push(format!("{} downloads", count(p.downloads)));
by.push(format!("from {}", p.source.label()));
if !p.license.is_empty() {
by.push(p.license.clone());