diff --git a/CommunityStore/locales/de.json b/CommunityStore/locales/de.json
index 373cfba..6eac3e6 100644
--- a/CommunityStore/locales/de.json
+++ b/CommunityStore/locales/de.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "Nach Beliebtheit",
+ "ui.publisher": "Herausgeber",
+ "ui.downloads_by_version": "Downloads nach Version",
+ "ui.downloads_all_time": "Insgesamt",
+ "ui.downloads_all_versions": "Alle Versionen ({count})",
+ "ui.downloads_collapse": "Verlauf einklappen",
+ "ui.downloads_no_files": "Keine Release-Dateien.",
+ "ui.downloads_note": "Gezählt werden alle Release-Dateien. Wählen Sie eine Version, um die Dateien anzuzeigen.",
+ "ui.release_downloads": "Downloads aller Release-Dateien"
}
diff --git a/CommunityStore/locales/en.json b/CommunityStore/locales/en.json
index b147daa..6914b1c 100644
--- a/CommunityStore/locales/en.json
+++ b/CommunityStore/locales/en.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "By popularity",
+ "ui.publisher": "Publisher",
+ "ui.downloads_by_version": "Downloads by version",
+ "ui.downloads_all_time": "All time",
+ "ui.downloads_all_versions": "All versions ({count})",
+ "ui.downloads_collapse": "Collapse history",
+ "ui.downloads_no_files": "No release files.",
+ "ui.downloads_note": "Counts include all release files. Select a version to see its files.",
+ "ui.release_downloads": "Downloads across all release assets"
}
diff --git a/CommunityStore/locales/fr.json b/CommunityStore/locales/fr.json
index 547e70d..0e2f1d7 100644
--- a/CommunityStore/locales/fr.json
+++ b/CommunityStore/locales/fr.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "Par popularité",
+ "ui.publisher": "Éditeur",
+ "ui.downloads_by_version": "Téléchargements par version",
+ "ui.downloads_all_time": "Depuis le début",
+ "ui.downloads_all_versions": "Toutes les versions ({count})",
+ "ui.downloads_collapse": "Réduire l’historique",
+ "ui.downloads_no_files": "Aucun fichier publié.",
+ "ui.downloads_note": "Tous les fichiers publiés sont comptés. Sélectionnez une version pour afficher ses fichiers.",
+ "ui.release_downloads": "Téléchargements des fichiers de toutes les versions"
}
diff --git a/CommunityStore/locales/pt-BR.json b/CommunityStore/locales/pt-BR.json
index 93def3f..0bf012c 100644
--- a/CommunityStore/locales/pt-BR.json
+++ b/CommunityStore/locales/pt-BR.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "Por popularidade",
+ "ui.publisher": "Publicador",
+ "ui.downloads_by_version": "Downloads por versão",
+ "ui.downloads_all_time": "Total acumulado",
+ "ui.downloads_all_versions": "Todas as versões ({count})",
+ "ui.downloads_collapse": "Recolher histórico",
+ "ui.downloads_no_files": "Nenhum arquivo nesta versão.",
+ "ui.downloads_note": "A contagem inclui todos os arquivos publicados. Selecione uma versão para ver seus arquivos.",
+ "ui.release_downloads": "Downloads dos arquivos de todas as versões"
}
diff --git a/CommunityStore/locales/ru.json b/CommunityStore/locales/ru.json
index e33953d..faa61dc 100644
--- a/CommunityStore/locales/ru.json
+++ b/CommunityStore/locales/ru.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "По популярности",
+ "ui.publisher": "Поставщик",
+ "ui.downloads_by_version": "Скачивания по версиям",
+ "ui.downloads_all_time": "За всё время",
+ "ui.downloads_all_versions": "Все версии ({count})",
+ "ui.downloads_collapse": "Свернуть историю",
+ "ui.downloads_no_files": "В релизе нет файлов.",
+ "ui.downloads_note": "Учитываются скачивания всех файлов релиза. Выберите версию, чтобы посмотреть разбивку по файлам.",
+ "ui.release_downloads": "Скачивания файлов всех релизов"
}
diff --git a/CommunityStore/locales/zh-Hans.json b/CommunityStore/locales/zh-Hans.json
index 4731ad7..b53bca2 100644
--- a/CommunityStore/locales/zh-Hans.json
+++ b/CommunityStore/locales/zh-Hans.json
@@ -405,5 +405,14 @@
"ui.language_fr": "Français",
"ui.language_de": "Deutsch",
"ui.language_pt-BR": "Português (Brasil)",
- "ui.language_zh-Hans": "简体中文"
+ "ui.language_zh-Hans": "简体中文",
+ "ui.sort_popularity": "按受欢迎程度",
+ "ui.publisher": "发布者",
+ "ui.downloads_by_version": "各版本下载次数",
+ "ui.downloads_all_time": "累计下载",
+ "ui.downloads_all_versions": "所有版本({count})",
+ "ui.downloads_collapse": "收起历史记录",
+ "ui.downloads_no_files": "此版本没有文件。",
+ "ui.downloads_note": "统计包含所有发布文件。选择版本可查看各文件的下载次数。",
+ "ui.release_downloads": "所有发行版附件的下载次数"
}
diff --git a/CommunityStore/releases.py b/CommunityStore/releases.py
index adc14ee..40e03f8 100644
--- a/CommunityStore/releases.py
+++ b/CommunityStore/releases.py
@@ -449,6 +449,7 @@ def ranked_assets(assets, repo, tag, platform=None, mac_arch=None):
candidates.sort(key=lambda candidate: (-candidate[0], candidate[1]["name"].casefold()))
return [{
**{key: item.get(key) for key in ("name", "browser_download_url", "digest")},
+ **({"download_count": item["download_count"]} if "download_count" in item else {}),
"compatible": bool(rank and isinstance(item.get("digest"), str)
and re.fullmatch(r"sha256:[a-f0-9]{64}", item["digest"])),
} for rank, item in candidates]
@@ -475,26 +476,71 @@ def available(release, *, stable_only=True):
and (not stable_only or not release.get("prerelease")) and any(asset["compatible"] for asset in release.get("assets", [])))
-def history(repo):
- validate_repo(repo)
- options = []
+def release_pages(path, *, missing_ok=False):
page = 1
while True:
- url = f"https://api.github.com/repos/{repo}/releases?per_page=100&page={page}"
+ url = f"https://api.github.com/{path}?per_page=100&page={page}"
try:
with request(url, GITHUB_JSON) as response:
data = json.loads(response.read(32 * 1024**2))
next_page = 'rel="next"' in response.headers.get("Link", "")
except HTTPError as error:
- if page != 1 or error.code != 404:
+ if not missing_ok or page != 1 or error.code != 404:
raise
- return []
- options.extend(release_option(item, repo) for item in data if not item.get("draft"))
+ return
+ yield from data
if not next_page:
- return options
+ return
page += 1
+def history(repo, *, index_downloads=False):
+ validate_repo(repo)
+ path = f"repos/{repo}/releases"
+ options = []
+ seen = set()
+ for item in release_pages(path, missing_ok=True):
+ key = item.get("id", item.get("tag_name"))
+ if item.get("draft") or key in seen:
+ continue
+ seen.add(key)
+ if index_downloads:
+ attached = item.get("assets")
+ if attached is None or len(attached) >= 30:
+ attached = release_pages(f"{path}/{item['id']}/assets")
+ assets = {asset["id"]: asset for asset in attached}
+ option = release_option({**item, "assets": assets.values()}, repo)
+ option["attachments"] = [{key: asset[key] for key in ("id", "name", "download_count")}
+ for asset in assets.values()]
+ option["download_count"] = sum(asset["download_count"] for asset in assets.values())
+ else:
+ option = release_option(item, repo)
+ options.append(option)
+ return options
+
+
+def download_series(repo, release):
+ """Return release asset counts, using indexed history when it is complete."""
+ history = release.get("history") or []
+ if history and all("attachments" in item and "download_count" in item for item in history):
+ return [{"tag": item["tag"], "date": item["publishedAt"], "prerelease": item["prerelease"],
+ "files": [[asset["name"], asset["download_count"]] for asset in item["attachments"]]}
+ for item in history]
+ validate_repo(repo)
+ path = f"repos/{repo}/releases"
+ rows = {}
+ for item in release_pages(path, missing_ok=True):
+ if item.get("draft"):
+ continue
+ assets = item["assets"]
+ if len(assets) >= 30:
+ assets = release_pages(f"{path}/{item['id']}/assets")
+ files = {asset["id"]: [asset["name"], asset["download_count"]] for asset in assets}
+ rows[item["id"]] = {"tag": item["tag_name"], "date": item["published_at"],
+ "prerelease": item["prerelease"], "files": list(files.values())}
+ return list(rows.values())
+
+
def release_history(repo, latest_tag):
return {"history": history(repo), "historyLatestTag": latest_tag, "historyChecked": int(time.time())}
diff --git a/CommunityStore/runtime.py b/CommunityStore/runtime.py
index 91db2a3..95065fa 100644
--- a/CommunityStore/runtime.py
+++ b/CommunityStore/runtime.py
@@ -31,7 +31,7 @@
PALETTE_WIDTH, PALETTE_HEIGHT = 1000, 780
PALETTE_MIN_WIDTH, PALETTE_MIN_HEIGHT = 300, 360
CHECK_INTERVALS = profiles.CHECK_INTERVALS
-MARKET_SORTS = ("stars-desc", "stars-asc", "release-desc", "release-asc", "name-asc", "name-desc")
+MARKET_SORTS = ("downloads-desc", "stars-desc", "stars-asc", "release-desc", "release-asc", "name-asc", "name-desc")
PALETTE_ACTIONS = frozenset((
"state", "openUrl", "report", "language", "githubSignIn", "githubCopyCode", "githubOpenDevice",
"githubCancel", "githubSignOut", "githubProfile",
@@ -925,6 +925,16 @@ def load_media(self, data):
elif kind == "avatar":
avatar = next((item["ownerAvatar"] for item in self.discovered.get(key, []) if item.get("ownerAvatar")), "")
work = lambda: {"avatar": self.artwork.avatar(avatar)} if avatar else {}
+ elif kind == "downloads":
+ release = self.latest.get(key, {})
+ if not release.get("isAddin") or not any(source["repo"] == key for source in self.sources()):
+ self.complete("artworkRejected", ticket)
+ return
+ session = self.github_session
+
+ def work():
+ with releases.use_session(session):
+ return {"downloads": releases.download_series(key, release)}
elif kind in ("card", "detail"):
source = next((item for item in self.sources() if item["repo"] == key), None)
release = self.latest.get(key, {})
@@ -1095,6 +1105,7 @@ def marketplace(self):
entry = {**source, **identity}
entry["artworkRevision"] = release.get("artworkRevision", "")
entry["description"] = release.get("description", "")
+ entry["totalDownloads"] = release.get("totalDownloads", 0)
entry["stars"] = release.get("stars", 0)
entry["tag"] = release["tag"]
entry["notes"] = release.get("notes", "")
diff --git a/CommunityStore/ui/assets/download.svg b/CommunityStore/ui/assets/download.svg
new file mode 100644
index 0000000..98911f8
--- /dev/null
+++ b/CommunityStore/ui/assets/download.svg
@@ -0,0 +1,3 @@
+
diff --git a/CommunityStore/ui/details.js b/CommunityStore/ui/details.js
index c7defbd..0e25374 100644
--- a/CommunityStore/ui/details.js
+++ b/CommunityStore/ui/details.js
@@ -248,15 +248,23 @@ function imageSlot(className, placeholder, record, fields, localImage = "") {
return slot;
}
-function stars(row) {
- const count = node("span", "stars");
- const formatted = row.stars.toLocaleString(state.language);
- count.title = t("github_stars");
+function repositoryCount(glyph, label, value) {
+ const count = node("span", "repository-count");
+ const formatted = (value ?? 0).toLocaleString(state.language);
+ count.title = t(label);
+ count.setAttribute("role", "img");
count.setAttribute("aria-label", count.title + " · " + formatted);
- count.append(icon("star"), document.createTextNode(formatted));
+ count.append(icon(glyph), document.createTextNode(formatted));
return count;
}
+function repositoryCounts(row) {
+ const group = node("span", "repository-counts");
+ group.append(repositoryCount("star", "github_stars", row.stars),
+ repositoryCount("download", "release_downloads", row.totalDownloads));
+ return group;
+}
+
let detail;
function detailButton(control, kind, key, name) {
@@ -431,6 +439,62 @@ document.getElementById("gallery-dialog").addEventListener("close", (event) => {
?.focus({preventScroll: true});
});
+function releaseDownloads(entry) {
+ const section = node("section", "release-downloads");
+ section.dataset.language = state.language;
+ section.dataset.tag = entry.tag;
+ const record = artworkFor(entry, "downloads");
+ watchArtwork(section, record, ({downloads}) => {
+ if (!downloads?.length || section.childElementCount) return;
+ const history = downloads.map(row => ({...row, count: row.files.reduce((sum, [, n]) => sum + n, 0)}))
+ .sort((a, b) => b.date.localeCompare(a.date));
+ const format = new Intl.NumberFormat(state.language);
+ const dates = new Intl.DateTimeFormat(state.language, {day: "numeric", month: "short", year: "numeric"});
+ const maximum = Math.max(1, ...history.map(row => row.count));
+ const heading = node("div", "download-heading");
+ const total = node("span", "download-total");
+ total.append(node("strong", "", format.format(history.reduce((sum, row) => sum + row.count, 0))),
+ node("span", "", t("downloads_all_time")));
+ heading.append(node("h2", "", t("downloads_by_version")), total);
+ section.append(heading);
+ const extra = node("div");
+ for (const [index, row] of history.entries()) {
+ const details = node("details", "download-release");
+ const summary = node("summary");
+ const tag = node("span", "download-tag", row.prerelease ? t("prerelease", {tag: row.tag}) : row.tag);
+ const date = new Date(row.date);
+ if (row.date && Number.isFinite(+date)) tag.append(node("small", "", dates.format(date)));
+ const track = node("span", history.length > 1 ? "download-track" : "");
+ const bar = node("span");
+ bar.style.width = (100 * row.count / maximum) + "%";
+ track.append(bar);
+ details.classList.toggle("current-release", row.tag === entry.tag);
+ summary.append(tag, track, node("span", "download-count", format.format(row.count)));
+ details.append(summary);
+ const files = node("div", "download-files");
+ for (const [name, count] of row.files) {
+ files.append(node("span", "", name), node("span", "download-count", format.format(count)));
+ }
+ if (!row.files.length) files.append(node("span", "", t("downloads_no_files")));
+ details.append(files);
+ (index < 5 ? section : extra).append(details);
+ }
+ if (extra.childElementCount) {
+ extra.hidden = true;
+ const label = t("downloads_all_versions", {count: format.format(history.length)});
+ const toggle = button(label, "download-more", () => {
+ extra.hidden = !extra.hidden;
+ toggle.textContent = extra.hidden ? label : t("downloads_collapse");
+ toggle.setAttribute("aria-expanded", String(!extra.hidden));
+ });
+ toggle.setAttribute("aria-expanded", "false");
+ section.append(extra, toggle);
+ }
+ section.append(node("p", "download-note", t("downloads_note")));
+ });
+ return section;
+}
+
function renderDetails(local, entry, installations) {
const fingerprint = JSON.stringify([detail.entry, local, entry, state.language, state.pending,
installations.map(({key, folder}) => [key, folder]),
@@ -476,7 +540,7 @@ function renderDetails(local, entry, installations) {
const owner = repository?.split("/")[0];
byline.append(node("span", "", owner || t("local_details")));
if (installedVersion || releaseVersion) byline.append(node("span", "version", installedVersion || releaseVersion));
- if (entry) byline.append(stars(entry));
+ if (entry) byline.append(repositoryCounts(entry));
const author = local?.author?.trim() || entry?.author?.trim();
if (author && author.toLowerCase() !== owner?.toLowerCase()) {
byline.append(node("span", "detail-author", t("addin_author", {author})));
@@ -529,9 +593,15 @@ function renderDetails(local, entry, installations) {
if (entry && !entry.available && !entry.matches.length) {
disclosure.push(node("p", "install-disclosure", t("compatibility_unavailable")));
}
+ let chart = sameEntry && target.querySelector(".release-downloads");
+ if (entry && (!chart || chart.dataset.language !== state.language || chart.dataset.tag !== entry.tag)) {
+ chart = releaseDownloads(entry);
+ }
target.replaceChildren(header, ...description, ...disclosure, gallery);
const readme = record && detailDocumentation(target, record, root, Boolean(previousReadme?.open));
- target.append(facts, notes, links);
+ target.append(facts, notes);
+ if (chart) target.append(chart);
+ target.append(links);
if (record) detailMedia(record, hero, row, gallery);
if (focusKey) focusDetailControl(focusKey);
else if (focusSelector) {
diff --git a/CommunityStore/ui/index.html b/CommunityStore/ui/index.html
index 07b16d7..299e914 100644
--- a/CommunityStore/ui/index.html
+++ b/CommunityStore/ui/index.html
@@ -53,6 +53,7 @@