Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

33 linesCodeBlameRaw
1import type { Route } from "./+types/person";
2import { buildCard } from "../../../lib/hovercard";
3import { identity, repos } from "../../../lib/services.server";
4import { requireUser } from "../../../lib/session.server";
5
6/**
7 * A person's card in Chat (components/chat/profile-card.tsx): their public
8 * profile as the hovercard has it, and the teams they are on in this
9 * workspace that the viewer can see. Kept a minute by the browser.
10 */
11export async function loader({ params, context, request }: Route.LoaderArgs) {
12 const viewer = requireUser(context, request);
13 // Guests see people's cards too: a card is their public profile, and teams only the viewer may see.
14 const [card, teams] = await Promise.all([
15 buildCard(
16 params.username,
17 viewer,
18 null,
19 {
20 profile: (username) => identity.profile(username),
21 accountId: async (username) => (await identity.userByUsername(username))?.id ?? null,
22 publicNamespaces: (id) => repos.publicNamespaces(id),
23 profileWorkspaces: (username, who, publicIn) => identity.profileWorkspaces(username, who, publicIn),
24 contributors: (path, who) => repos.contributors(path, who),
25 },
26 Date.now(),
27 ).catch(() => null),
28 identity.userTeams(viewer, params.owner, params.username).catch(() => null),
29 ]);
30 const headers = { "cache-control": "private, max-age=60", vary: "Cookie" };
31 if (!card || card.kind !== "user") return Response.json({ error: "not_found" }, { status: 404, headers });
32 return Response.json({ ...card, teams: teams?.ok ? teams.value.map((team) => ({ slug: team.slug, name: team.name })) : [] }, { headers });
33}