Files
botfights/server/src/routes/stats.ts
T

20 lines
591 B
TypeScript
Raw Normal View History

2026-03-09 00:15:20 +00:00
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 })
})