Show mod download counts and count installs from the loader

This commit is contained in:
Justin Oros
2026-09-28 12:47:34 -07:00
parent df59c7edbb
commit 079caa599d
2 changed files with 27 additions and 2 deletions
+17 -1
View File
@@ -52,6 +52,20 @@ def latest_release(full_name):
raise
def total_downloads(full_name):
total = 0
page = 1
while True:
batch = api(f"/repos/{full_name}/releases?per_page=100&page={page}")
if not batch:
break
for release in batch:
for asset in release.get("assets", []):
total += asset.get("download_count", 0)
page += 1
return total
def zip_asset(release):
for asset in release.get("assets", []):
if asset["name"].lower().endswith(".zip"):
@@ -138,7 +152,8 @@ def build_mod(repo):
print(f"skip {repo['name']}: no DLL at the top of the zip")
shutil.rmtree(OUT.joinpath(*base.parts), ignore_errors=True)
return None
print(f"mod {mod_id} {version} ({len(files)} files)")
downloads = total_downloads(repo["full_name"])
print(f"mod {mod_id} {version} ({len(files)} files, {downloads} downloads)")
return {
"id": mod_id,
"name": meta.get("name") or mod_id,
@@ -152,6 +167,7 @@ def build_mod(repo):
"releaseUrl": release["html_url"],
"downloadUrl": asset["browser_download_url"],
"published": release.get("published_at"),
"downloads": downloads,
"base": f"{base}/",
"dll": dll,
"manifestPath": manifest_path,
+10 -1
View File
@@ -275,10 +275,15 @@ function installRedloader() {
});
}
function countDownload(mod) {
if (mod.downloadUrl) fetch(mod.downloadUrl, { mode: "no-cors", cache: "no-store" }).catch(() => {});
}
function installMod(mod) {
return run(async () => {
const before = state.statuses.get(mod.id);
await installPackage(mod, mod.roots);
countDownload(mod);
const message = before && before.installed ? `${mod.name} updated to ${mod.version}.` : `${mod.name} ${mod.version} installed.`;
setStatus(message, "ok");
});
@@ -294,7 +299,10 @@ function removeMod(mod) {
function updateAll(mods) {
return run(async () => {
for (const mod of mods) await installPackage(mod, mod.roots);
for (const mod of mods) {
await installPackage(mod, mod.roots);
countDownload(mod);
}
setStatus(`Updated ${mods.length} mod${mods.length === 1 ? "" : "s"}.`, "ok");
});
}
@@ -430,6 +438,7 @@ function modRow(mod) {
mod.description ? el("p", { class: "desc" }, mod.description) : null,
el("p", { class: "meta" },
versionLine(mod, status),
typeof mod.downloads === "number" ? el("span", {}, `${mod.downloads.toLocaleString()} downloads`) : null,
el("a", { href: mod.releaseUrl, target: "_blank", rel: "noopener" }, supportsFs ? "Release notes" : "Download"),
),
),