Show mod download counts and count installs from the loader
This commit is contained in:
1 parent
df59c7edbb
commit
079caa599d
2 files changed
+27
-2
No files matched your search
@@ -52,6 +52,20 @@ def latest_release(full_name):
|
|||||||
raise
|
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):
|
def zip_asset(release):
|
||||||
for asset in release.get("assets", []):
|
for asset in release.get("assets", []):
|
||||||
if asset["name"].lower().endswith(".zip"):
|
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")
|
print(f"skip {repo['name']}: no DLL at the top of the zip")
|
||||||
shutil.rmtree(OUT.joinpath(*base.parts), ignore_errors=True)
|
shutil.rmtree(OUT.joinpath(*base.parts), ignore_errors=True)
|
||||||
return None
|
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 {
|
return {
|
||||||
"id": mod_id,
|
"id": mod_id,
|
||||||
"name": meta.get("name") or mod_id,
|
"name": meta.get("name") or mod_id,
|
||||||
@@ -152,6 +167,7 @@ def build_mod(repo):
|
|||||||
"releaseUrl": release["html_url"],
|
"releaseUrl": release["html_url"],
|
||||||
"downloadUrl": asset["browser_download_url"],
|
"downloadUrl": asset["browser_download_url"],
|
||||||
"published": release.get("published_at"),
|
"published": release.get("published_at"),
|
||||||
|
"downloads": downloads,
|
||||||
"base": f"{base}/",
|
"base": f"{base}/",
|
||||||
"dll": dll,
|
"dll": dll,
|
||||||
"manifestPath": manifest_path,
|
"manifestPath": manifest_path,
|
||||||
|
|||||||
+10
-1
@@ -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) {
|
function installMod(mod) {
|
||||||
return run(async () => {
|
return run(async () => {
|
||||||
const before = state.statuses.get(mod.id);
|
const before = state.statuses.get(mod.id);
|
||||||
await installPackage(mod, mod.roots);
|
await installPackage(mod, mod.roots);
|
||||||
|
countDownload(mod);
|
||||||
const message = before && before.installed ? `${mod.name} updated to ${mod.version}.` : `${mod.name} ${mod.version} installed.`;
|
const message = before && before.installed ? `${mod.name} updated to ${mod.version}.` : `${mod.name} ${mod.version} installed.`;
|
||||||
setStatus(message, "ok");
|
setStatus(message, "ok");
|
||||||
});
|
});
|
||||||
@@ -294,7 +299,10 @@ function removeMod(mod) {
|
|||||||
|
|
||||||
function updateAll(mods) {
|
function updateAll(mods) {
|
||||||
return run(async () => {
|
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");
|
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,
|
mod.description ? el("p", { class: "desc" }, mod.description) : null,
|
||||||
el("p", { class: "meta" },
|
el("p", { class: "meta" },
|
||||||
versionLine(mod, status),
|
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"),
|
el("a", { href: mod.releaseUrl, target: "_blank", rel: "noopener" }, supportsFs ? "Release notes" : "Download"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in new issue
Block a user