20 lines
591 B
TypeScript
20 lines
591 B
TypeScript
import { Hono } from 'hono'
|
|||
|
|
import { getPublicStats } from '../engine/analytics.js'
|
||
|
|
|
||
|
|
export const statsRouter = new Hono()
|
||
|
|
|
||
|
|
// GET /public — aggregate stats for last 30 days, no PII
|
||
|
|
statsRouter.get('/public', (c) => {
|
||
|
|
const days = Math.min(parseInt(c.req.query('days') || '30'), 90)
|
||
|
|
const rows = getPublicStats(days)
|
||
|
|
|
||
|
|
// Group by date for easier consumption
|
||
|
|
const byDate: Record<string, Record<string, number>> = {}
|
||
|
|
for (const row of rows) {
|
||
|
|
if (!byDate[row.date]) byDate[row.date] = {}
|
||
|
|
byDate[row.date][row.metric] = row.value
|
||
|
|
}
|
||
|
|
|
||
|
|
return c.json({ stats: byDate })
|
||
|
|
})
|