import type { Hono } from "hono"; import { html } from "../pages/html.ts"; import { plural } from "../pages/layout.ts"; import { downloadsByDay, repoDownloads, topFiles, utcDay } from "../releases/releases.ts"; import { type AdminContext, adminPage } from "./console.ts"; import { allRepos } from "./store.ts"; const DAYS_SHOWN = 30; const TOP_FILES = 10; const DAY_MS = 24 * 60 * 60 * 1000; /** §24's Downloads section: the last 30 days, each repo's totals and the top files. */ export function registerDownloads(app: Hono, ctx: AdminContext): void { app.get("/admin/downloads", (c) => { // An unknown repo narrows nothing, as the issues list treats one. const repos = allRepos(ctx.kepr).map((repo) => repo.name); const repo = repos.find((name) => name === c.req.query("repo")) ?? ""; const now = Date.now(); const days = Array.from({ length: DAYS_SHOWN }, (_, i) => utcDay(now - (DAYS_SHOWN - 1 - i) * DAY_MS), ); const since = days[0] as string; const counts = downloadsByDay(ctx.kepr, since, repo); const peak = Math.max(1, ...counts.values()); const option = (name: string) => html``; const body = html`
${row.repo} ${row.version} ${row.platform}
`, )}