| 1 | import { Hono } from "hono"; |
| 2 | import type { Bindings } from "../types"; |
| 3 | |
| 4 | const records = new Hono<{ Bindings: Bindings }>(); |
| 5 | |
| 6 | records.get("/:did", async (c) => { |
| 7 | try { |
| 8 | const db = c.env.DB; |
| 9 | const did = c.req.param("did"); |
| 10 | const limit = Number(c.req.query("limit")) || 20; |
| 11 | const offset = Number(c.req.query("offset")) || 0; |
| 12 | |
| 13 | const { results } = await db |
| 14 | .prepare( |
| 15 | `SELECT * FROM repo_records |
| 16 | WHERE did = ? AND collection = 'site.standard.document' |
| 17 | ORDER BY rkey DESC |
| 18 | LIMIT ? OFFSET ?` |
| 19 | ) |
| 20 | .bind(did, limit, offset) |
| 21 | .all(); |
| 22 | |
| 23 | return c.json({ |
| 24 | did, |
| 25 | count: results?.length || 0, |
| 26 | limit, |
| 27 | offset, |
| 28 | records: results || [], |
| 29 | }); |
| 30 | } catch (error) { |
| 31 | return c.json( |
| 32 | { error: "Failed to fetch records", details: String(error) }, |
| 33 | 500 |
| 34 | ); |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | export default records; |