Sink/server/api/logs/events.ts
ccbikai 0dd263c354 feat: enhance realtime dashboard with time filters
Implements comprehensive time filtering and visualization improvements:

- Adds time range picker with presets from 5min to 24h
- Enhances chart visualization with minute-level granularity
- Updates globe visualization to respond to time/filter changes
- Implements animated event log display
- Swaps primary/secondary color scheme for better contrast

Improves realtime data handling with automatic updates and proper cleanup on unmount. Includes i18n support for new time picker UI across all supported languages.
2025-05-18 19:06:28 +08:00

39 lines
1.1 KiB
TypeScript

import type { H3Event } from 'h3'
import { QuerySchema } from '@@/schemas/query'
import { date2unix } from '~/utils/time'
const { select } = SqlBricks
function query2sql(query: Query, event: H3Event): string {
const filter = query2filter(query)
const { dataset } = useRuntimeConfig(event)
const sql = select(`*`).from(dataset).where(filter).orderBy('timestamp DESC')
appendTimeFilter(sql, query)
return sql.toString()
}
interface WAEEvents {
[key: string]: string
}
function events2logs(events: WAEEvents[]) {
return events.map((event) => {
const blobs = Array.from({ length: Object.keys(blobsMap).length }).fill(0).reduce<string[]>((_, _c, i) => {
_.push(event[`blob${i + 1}`])
return _
}, [])
return {
...blobs2logs(blobs),
id: crypto.randomUUID(),
timestamp: date2unix(new Date(`${event.timestamp}Z`)),
}
})
}
export default eventHandler(async (event) => {
const query = await getValidatedQuery(event, QuerySchema.parse)
const sql = query2sql(query, event)
const logs = await useWAE(event, sql) as { data: WAEEvents[] }
return events2logs(logs?.data || [])
})