| 1 | import { Hono } from "hono"; |
| 2 | import type { AppEnv } from "../env"; |
| 3 | import { toPublicUser } from "../types"; |
| 4 | import { repos } from "../db"; |
| 5 | import { ApiError } from "../http/errors"; |
| 6 | |
| 7 | const users = new Hono<AppEnv>(); |
| 8 | |
| 9 | // Public profile. Suspended/deleted accounts are indistinguishable from missing. |
| 10 | users.get("/:handle", async (c) => { |
| 11 | const handle = c.req.param("handle").toLowerCase(); |
| 12 | const row = await repos(c.env).users.byHandle(handle); |
| 13 | if (!row || row.status !== "active") throw new ApiError(404, "not_found", "No such profile."); |
| 14 | return c.json({ user: toPublicUser(row) }); |
| 15 | }); |
| 16 | |
| 17 | export default users; |
| 18 |