Skip to content

g1t/apps/web/app/lib/about.server.ts

32 lines1,353 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Merge branch 'main' into worktree-agent-a69aeabc4b0deeb971/**
2 * The Files page's About, streamed in after the files: what the default
3 * branch says, stars and releases from repos; how many watch it from the
4 * inbox; packages published from it. Each is its own promise, so a slow
5 * one holds up only its own section, and a failure shows the section
6 * without it rather than failing the page.
7 */
8import type { PackageSummary, RepoAbout, RepoPath, Viewer } from "@g1t/contracts";
9
10import type { AboutData } from "../components/repo-about";
11import { inbox, packages, repos } from "./services.server";
12
13/** How long a section waits before it shows without its answer. */
14const WAIT_MS = 4_000;
15
16function within<T>(promise: Promise<T>): Promise<T | null> {
17 return Promise.race([promise.catch(() => null), new Promise<null>((resolve) => setTimeout(() => resolve(null), WAIT_MS))]);
18}
19
20export function aboutOf(path: RepoPath, viewer: Viewer): Promise<RepoAbout | null> {
21 return repos.about(path, viewer).then((found) => (found.ok ? found.value : null));
22}
23
24export function aboutFor(path: RepoPath, viewer: Viewer, repoId: string): AboutData {
25 return {
26 about: within(aboutOf(path, viewer)),
27 watchers: within(inbox.watchers(repoId)),
28 packages: within(
29 packages.list(path.namespace, viewer, { repoId }).then((found): PackageSummary[] | null => (found.ok ? found.value : null)),
30 ),
31 };
32}

This file's history is long; its oldest lines are credited to the oldest commit read.