2026-05-27 15:19:31 +08:00
2026-05-27 15:19:31 +08:00
2026-05-27 15:19:31 +08:00
2026-05-08 17:24:33 +08:00
2026-04-20 20:09:23 +08:00
2026-05-27 15:19:31 +08:00

New API Analytics

Internal analytics dashboard for New API usage logs. The app reads PostgreSQL log data and visualizes calls, token consumption, model usage, channel usage, per-user aggregation, and raw request logs.

Requirements

  • Bun for local development and tests.
  • Node.js 20 for the production Docker image.
  • PostgreSQL database with New API tables described in docs/database.md.
  • PG_CONNECTION_STRING set to a PostgreSQL connection string.

Local Development

bun install
bun run dev

Open http://localhost:3000.

Verification

bun test
bun run lint
bun run build

bun test covers parser helpers, metric conversion, query behavior, cache behavior, theme helpers, and selected API route guardrails.

Configuration

Create an environment file or export:

PG_CONNECTION_STRING=postgres://user:password@host:5432/database

The app uses this variable in lib/db.ts to create a pg connection pool.

Deployment

The included Dockerfile builds a standalone Next.js output and starts server.js on port 8019.

docker compose up -d --build

docker-compose.yml expects .env.production and an external Docker network named sinobridge.

Operational Notes

  • API query parameters are validated at the route layer. Invalid integers or reversed date ranges return HTTP 400.
  • Ranking limits are capped at 100 rows per request.
  • Log page size is capped at 200 rows per request.
  • Query results are cached in-process for 120 seconds with a 500-entry cap.
  • Metric definitions and quota conversion are documented in docs/metrics.md.
Description
New API analytics dashboard
Readme 363 KiB
Languages
TypeScript 87.2%
CSS 12.1%
Dockerfile 0.4%
JavaScript 0.3%