import { Router } from 'express'; import { getStorageStats, getTotalStorageSize, getDownloadsToday, getRecentDownloads, getMediaFileCount, getAutoDownloadUsers, getAutoScrapeJobs, getAuthConfig, } from './db.js'; import { getActiveDownloadCount, getActiveDownloadsList } from './download.js'; import { getActiveScrapeCount, getActiveScrapesList } from './scrape.js'; const router = Router(); router.get('/api/dashboard', (req, res) => { try { const storageStats = getStorageStats(); const totalStorage = getTotalStorageSize(); const totalFiles = getMediaFileCount(); const downloadsToday = getDownloadsToday(); const recentDownloads = getRecentDownloads(10); const autoDownloads = getAutoDownloadUsers(); const autoScrapes = getAutoScrapeJobs(); res.json({ stats: { totalFiles, totalStorage, totalFolders: storageStats.length, downloadsToday, }, topFolders: storageStats.slice(0, 10), activeJobs: { downloads: getActiveDownloadCount(), scrapes: getActiveScrapeCount(), downloadList: getActiveDownloadsList(), scrapeList: getActiveScrapesList(), }, auth: { configured: !!getAuthConfig(), }, scheduler: { autoDownloadCount: autoDownloads.length, autoScrapeCount: autoScrapes.length, }, recentDownloads, }); } catch (err) { console.error('[dashboard] Error:', err.message); res.status(500).json({ error: err.message }); } }); export default router;