11import { Hono } from "hono" ;
22import type { AppContext } from "@/types/app.js" ;
3- import {
4- queryRawRows ,
5- queryStats ,
6- queryAnalytics ,
7- startMigration ,
8- VALID_GRANULARITIES ,
9- ALLOWED_FILTERS ,
10- type Granularity ,
11- } from "@/analytics.js" ;
3+ import { startMigration } from "@/analytics.js" ;
124
135const admin = new Hono < AppContext > ( ) ;
146
@@ -19,59 +11,6 @@ admin.use("*", async (c, next) => {
1911 await next ( ) ;
2012} ) ;
2113
22- admin . get ( "/telemetry/system-info" , async ( c ) => {
23- const limit = Math . min ( Number ( c . req . query ( "limit" ) || 100 ) , 500 ) ;
24- const offset = Number ( c . req . query ( "offset" ) || 0 ) ;
25-
26- const data = await queryRawRows ( limit , offset ) ;
27-
28- return c . json ( { data, limit, offset } ) ;
29- } ) ;
30-
31- admin . get ( "/telemetry/system-info/stats" , async ( c ) => {
32- const granularity = ( c . req . query ( "granularity" ) || "daily" ) as Granularity ;
33- if ( ! VALID_GRANULARITIES . includes ( granularity ) ) {
34- return c . json (
35- {
36- error : `Invalid granularity. Must be one of: ${ VALID_GRANULARITIES . join ( ", " ) } ` ,
37- } ,
38- 400 ,
39- ) ;
40- }
41-
42- const periods = Math . min ( Number ( c . req . query ( "periods" ) || 30 ) , 365 ) ;
43-
44- const data = await queryStats ( granularity , periods ) ;
45-
46- return c . json ( { data, granularity, periods } ) ;
47- } ) ;
48-
49- admin . get ( "/analytics" , async ( c ) => {
50- const granularity = ( c . req . query ( "granularity" ) || "daily" ) as Granularity ;
51- if ( ! VALID_GRANULARITIES . includes ( granularity ) ) {
52- return c . json (
53- {
54- error : `Invalid granularity. Must be one of: ${ VALID_GRANULARITIES . join ( ", " ) } ` ,
55- } ,
56- 400 ,
57- ) ;
58- }
59-
60- const periods = Math . min ( Number ( c . req . query ( "periods" ) || 30 ) , 365 ) ;
61-
62- const filters : Record < string , string > = { } ;
63- for ( const key of Object . keys ( ALLOWED_FILTERS ) ) {
64- const value = c . req . query ( key ) ;
65- if ( value ) {
66- filters [ key ] = value ;
67- }
68- }
69-
70- const data = await queryAnalytics ( granularity , periods , filters ) ;
71-
72- return c . json ( { data, filters, granularity, periods } ) ;
73- } ) ;
74-
7514admin . post ( "/telemetry/migrate" , ( c ) => {
7615 if ( ! startMigration ( ) ) {
7716 return c . json ( { error : "Migration already in progress" } , 409 ) ;
0 commit comments