feat: add backend analytics wrapper, config/consent API routes

This commit is contained in:
ashim-hq
2026-04-22 19:03:23 +08:00
parent 4904e8d140
commit 075f017dbf
6 changed files with 930 additions and 5 deletions
+13
View File
@@ -8,6 +8,7 @@ import Fastify from "fastify";
import { env } from "./config.js";
import { db, schema } from "./db/index.js";
import { runMigrations } from "./db/migrate.js";
import { initAnalytics, shutdownAnalytics } from "./lib/analytics.js";
import { startCleanupCron } from "./lib/cleanup.js";
import { ensureAiDirs, recoverInterruptedInstalls } from "./lib/feature-status.js";
import { shutdownWorkerPool } from "./lib/worker-pool.js";
@@ -15,6 +16,7 @@ import { requirePermission } from "./permissions.js";
import { authMiddleware, authRoutes, ensureDefaultAdmin } from "./plugins/auth.js";
import { registerStatic } from "./plugins/static.js";
import { registerUpload } from "./plugins/upload.js";
import { analyticsRoutes } from "./routes/analytics.js";
import { apiKeyRoutes } from "./routes/api-keys.js";
import { auditLogRoutes } from "./routes/audit-log.js";
import { registerBatchRoutes } from "./routes/batch.js";
@@ -49,6 +51,7 @@ function ensureInstanceId() {
}
ensureInstanceId();
initAnalytics();
// Mark any jobs left in processing/queued from a previous unclean shutdown
recoverStaleJobs();
@@ -143,6 +146,9 @@ await apiKeyRoutes(app);
// Settings routes
await settingsRoutes(app);
// Analytics config and consent routes
await analyticsRoutes(app);
// Feature management routes (AI feature bundle install/uninstall)
await registerFeatureRoutes(app);
@@ -273,6 +279,13 @@ async function shutdown(signal: string) {
// AI package may not be available
}
try {
await shutdownAnalytics();
console.log("Analytics flushed");
} catch {
// analytics shutdown is best-effort
}
try {
const { sqlite: sqliteConn } = await import("./db/index.js");
sqliteConn.close();