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.
| About: license, languages, contributors, stars, releases and activity beside the files | 1 | /** |
| 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 | */ | |
| 8 | import type { PackageSummary, RepoAbout, RepoPath, Viewer } from "@g1t/contracts"; | |
| 9 | ||
| 10 | import type { AboutData } from "../components/repo-about"; | |
| 11 | import { inbox, packages, repos } from "./services.server"; | |
| 12 | ||
| 13 | /** How long a section waits before it shows without its answer. */ | |
| 14 | const WAIT_MS = 4_000; | |
| 15 | ||
| 16 | function 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 | ||
| 20 | export function aboutOf(path: RepoPath, viewer: Viewer): Promise<RepoAbout | null> { | |
| 21 | return repos.about(path, viewer).then((found) => (found.ok ? found.value : null)); | |
| 22 | } | |
| 23 | ||
| 24 | export 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 | } |