feat: implement visual analytics and activity charts
This commit is contained in:
@@ -59,6 +59,10 @@ export async function createWebServer(config: WebServerConfig = {}): Promise<Web
|
||||
// Interval for broadcasting stats to all connected WS clients
|
||||
let statsBroadcastInterval: Timer | undefined;
|
||||
|
||||
// Cache for activity stats (heavy aggregation)
|
||||
let cachedActivity: { data: any, timestamp: number } | null = null;
|
||||
const ACTIVITY_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
const server = serve({
|
||||
port,
|
||||
hostname,
|
||||
@@ -97,6 +101,27 @@ export async function createWebServer(config: WebServerConfig = {}): Promise<Web
|
||||
}
|
||||
}
|
||||
|
||||
if (url.pathname === "/api/stats/activity") {
|
||||
try {
|
||||
const now = Date.now();
|
||||
if (cachedActivity && (now - cachedActivity.timestamp < ACTIVITY_CACHE_TTL)) {
|
||||
return Response.json(cachedActivity.data);
|
||||
}
|
||||
|
||||
const { dashboardService } = await import("@shared/modules/dashboard/dashboard.service");
|
||||
const activity = await dashboardService.getActivityAggregation();
|
||||
|
||||
cachedActivity = { data: activity, timestamp: now };
|
||||
return Response.json(activity);
|
||||
} catch (error) {
|
||||
console.error("Error fetching activity stats:", error);
|
||||
return Response.json(
|
||||
{ error: "Failed to fetch activity statistics" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Administrative Actions
|
||||
if (url.pathname.startsWith("/api/actions/") && req.method === "POST") {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user