1import type { Hono } from "hono";2import type { ReleaseFile } from "../bucket/repo.ts";3import { saveByPrefix } from "../mirror/queries.ts";4import { downloadCounts, type Release, visibleReleases } from "../releases/releases.ts";5import { type Html, html } from "./html.ts";6import {7 cacheFor,8 formatDate,9 formatSize,10 notFound,11 openPublicRepo,12 type PageContext,13 type PublicRepo,14 page,15 plural,16} from "./layout.ts";17import { renderMarkdown } from "./markdown.ts";181920const PLATFORM_LABELS: Record<string, string> = {21 "linux-x86_64": "Linux · x86_64",22 "linux-aarch64": "Linux · ARM64",23 "macos-aarch64": "macOS · Apple Silicon",24 "macos-x86_64": "macOS · Intel",25 "windows-x86_64": "Windows · x86_64",26 "android-arm64": "Android · ARM64",27 "android-x86": "Android · x86_64",28};293031export function registerReleasesPage(app: Hono, ctx: PageContext): void {32 app.get("/:repo/releases", (c) => {33 const repo = openPublicRepo(ctx, c.req.param("repo"));34 if (!repo) return notFound(c, ctx);35 const name = repo.settings.name;36 const releases = visibleReleases(ctx.kepr, repo.mirror, name);37 const counts = downloadCounts(ctx.kepr, name);38 cacheFor(c, false);39 return c.html(40 page(ctx, {41 title: `builds · ${name}`,42 description: `Releases of ${name}, with downloads and checksums.`,43 path: `/${name}/releases`,44 body: html`<p class="breadcrumb mono"><a href="/${name}">${name}</a></p>45<h1 class="file-page-title">builds</h1>46<section class="repo-section">47${releases.length > 0 ? releases.map((release) => releaseBlock(repo, release, counts)) : html`<p class="muted mono save-empty">no releases yet</p>`}48</section>`,49 }),50 );51 });52}5354function releaseBlock(repo: PublicRepo, release: Release, counts: Map<string, number>): Html {55 const name = repo.settings.name;56 const save = saveByPrefix(repo.mirror, release.save);57 58 const saveLink =59 save && !save.is_checkpoint60 ? html`<a class="history-id" href="/${name}/saves/${save.id}">${save.id}</a>`61 : html`<span class="history-id">${release.save}</span>`;62 63 const notes =64 release.notes !== ""65 ? renderMarkdown(release.notes, { repo: name, dir: "", at: null })66 : html`<p>${save?.message ?? `Release ${release.version} of ${name}.`}</p>`;67 return html`<article class="release" id="${release.version}">68<p class="release-head"><span class="release-version">v${release.version}</span>${saveLink}<span class="history-when">${formatDate(release.publishedAt)}</span></p>69<div class="release-notes markdown">${notes}</div>70<div class="release-files">71${release.files.map((file) => fileRow(name, release.version, file, counts.get(`${release.version}/${file.platform}`) ?? 0))}72</div>73</article>`;74}7576function fileRow(repo: string, version: string, file: ReleaseFile, downloads: number): Html {77 const hint = installHint(file.name);78 79 return html`<div class="release-file">80<p class="release-file-head"><span class="release-platform">${PLATFORM_LABELS[file.platform]}</span><a class="release-download mono" href="/${repo}/releases/${version}/${repo}-${file.platform}">↓ ${file.name}</a><span class="release-meta mono">${formatSize(file.size)} · ${plural(downloads, "download")}</span></p>81<p class="release-sha mono"><span class="muted">sha256</span> ${file.sha256}</p>82${hint && html`<p class="release-hint muted">${hint}</p>`}83</div>`;84}858687function installHint(fileName: string): string {88 const lower = fileName.toLowerCase();89 if (lower.endsWith(".app.zip")) return "unzip and drag to Applications";90 if (lower.endsWith(".apk")) {91 return "open on your device to install — allow installs from this source if prompted";92 }93 return "";94}