| 1 | import { Hono } from "hono"; |
| 2 | import { z } from "zod"; |
| 3 | import type { AppEnv } from "../env"; |
| 4 | import { repos } from "../db"; |
| 5 | import { parseQuery } from "../lib/validation"; |
| 6 | |
| 7 | const activity = new Hono<AppEnv>(); |
| 8 | |
| 9 | const FeedQuerySchema = z.object({ |
| 10 | limit: z.coerce.number().int().min(1).max(100).default(30), |
| 11 | }); |
| 12 | |
| 13 | // The homepage live feed: publish/update/star/milestone events. Raw install |
| 14 | // pings are excluded here (they feed the trending rank) so the feed stays social. |
| 15 | activity.get("/", async (c) => { |
| 16 | const { limit } = parseQuery(c, FeedQuerySchema); |
| 17 | const rows = await repos(c.env).events.recent(limit); |
| 18 | const events = rows.map((e) => ({ |
| 19 | type: e.type, |
| 20 | slug: e.slug, |
| 21 | actor: e.actor_handle, |
| 22 | summary: e.summary, |
| 23 | createdAt: e.created_at, |
| 24 | })); |
| 25 | return c.json({ events }); |
| 26 | }); |
| 27 | |
| 28 | export default activity; |
| 29 |