mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-09 11:19:36 +01:00
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
const express = require('express')
|
|
|
|
/**
|
|
* Statistics API Routes
|
|
* GET / - Get lightweight statistics
|
|
* GET /enhanced - Get full statistics with historical data
|
|
*/
|
|
function createStatsRouter(dependencies) {
|
|
const router = express.Router()
|
|
const { statisticsStore, mailProcessingService, imapService, config } = dependencies
|
|
|
|
if (!config.http.statisticsEnabled) {
|
|
router.all('*', (req, res) => {
|
|
res.apiError('Statistics are disabled', 'FEATURE_DISABLED', 503)
|
|
})
|
|
return router
|
|
}
|
|
|
|
/**
|
|
* GET / - Get lightweight statistics (no historical analysis)
|
|
*/
|
|
router.get('/', async(req, res, next) => {
|
|
try {
|
|
const stats = statisticsStore.getLightweightStats()
|
|
|
|
res.apiSuccess(stats)
|
|
} catch (error) {
|
|
next(error)
|
|
}
|
|
})
|
|
|
|
/**
|
|
* GET /enhanced - Get full statistics with historical data
|
|
*/
|
|
router.get('/enhanced', async(req, res, next) => {
|
|
try {
|
|
// Analyze all existing emails for historical data
|
|
if (mailProcessingService) {
|
|
const allMails = mailProcessingService.getAllMailSummaries()
|
|
statisticsStore.analyzeHistoricalData(allMails)
|
|
}
|
|
|
|
const stats = statisticsStore.getEnhancedStats()
|
|
|
|
res.apiSuccess(stats)
|
|
} catch (error) {
|
|
next(error)
|
|
}
|
|
})
|
|
|
|
return router
|
|
}
|
|
|
|
module.exports = createStatsRouter
|