import { Router, Response } from 'express'; import { authMiddleware, adminMiddleware, AuthRequest } from '../middleware/auth'; import { activeSessions } from '../services/cliBridge'; import { User, Video } from '../models'; const router = Router(); router.use(authMiddleware); router.use(adminMiddleware); // GET /api/admin/queue -- view active CLI sessions router.get('/queue', async (_req: AuthRequest, res: Response) => { try { const sessions = Array.from(activeSessions.entries()).map(([id, session]) => ({ sessionId: id, userId: session.userId, videoId: session.videoId, logCount: session.logs.length, })); res.json({ activeSessions: sessions, count: sessions.length }); } catch (error) { res.status(500).json({ error: 'Failed to fetch queue status.' }); } }); // GET /api/admin/stats -- overview stats router.get('/stats', async (_req: AuthRequest, res: Response) => { try { const userCount = await User.countDocuments(); const videoCount = await Video.countDocuments(); const pendingVideos = await Video.countDocuments({ status: 'generating' }); res.json({ users: userCount, videos: videoCount, pendingVideos, activeCLISessions: activeSessions.size, }); } catch (error) { res.status(500).json({ error: 'Failed to fetch stats.' }); } }); export default router;