mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-09 11:19:36 +01:00
[Chore]: Misc. V2 patches
This commit is contained in:
parent
2f58eacfa7
commit
c56ec92ce5
7 changed files with 62 additions and 31 deletions
BIN
.github/assets/stats.png
vendored
Normal file
BIN
.github/assets/stats.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 250 KiB |
|
|
@ -42,9 +42,9 @@ All data is being removed 48hrs after they have reached the mail server.
|
|||
|
||||
## Screenshots
|
||||
|
||||
| Homepage | Account Panel |
|
||||
|:---:|:---:|
|
||||
| <img src=".github/assets/home.png" width="500px" height="300px" style="object-fit: fit;"> | <img src=".github/assets/account.png" width="500px" height="300px" style="object-fit: fit;"> |
|
||||
| Homepage | Account Panel | Stats Page |
|
||||
|:---:|:---:|:---:|
|
||||
| <img src=".github/assets/home.png" width="500px" height="300px" style="object-fit: fit;"> | <img src=".github/assets/account.png" width="500px" height="300px" style="object-fit: fit;"> | <img src=".github/assets/stats.png" width="500px" height="300px" style="object-fit: fit;"> |
|
||||
|
||||
| Inbox | Email using HTML and CSS | Attachments and Cryptographic Keys view |
|
||||
|:---:|:---:|:---:|
|
||||
|
|
|
|||
10
app.js
10
app.js
|
|
@ -5,7 +5,7 @@
|
|||
const config = require('./application/config')
|
||||
const debug = require('debug')('48hr-email:app')
|
||||
const Helper = require('./application/helper')
|
||||
|
||||
const helper = new(Helper)
|
||||
const { app, io, server } = require('./infrastructure/web/web')
|
||||
const ClientNotification = require('./infrastructure/web/client-notification')
|
||||
const ImapService = require('./application/imap-service')
|
||||
|
|
@ -95,10 +95,14 @@ const mailProcessingService = new MailProcessingService(
|
|||
debug('Mail processing service initialized')
|
||||
|
||||
// Initialize statistics with current count
|
||||
imapService.on(ImapService.EVENT_INITIAL_LOAD_DONE, () => {
|
||||
imapService.on(ImapService.EVENT_INITIAL_LOAD_DONE, async() => {
|
||||
const count = mailProcessingService.getCount()
|
||||
statisticsStore.initialize(count)
|
||||
debug(`Statistics initialized with ${count} emails`)
|
||||
|
||||
// Get and set the largest UID for all-time total
|
||||
const largestUid = await helper.getLargestUid(imapService)
|
||||
statisticsStore.updateLargestUid(largestUid)
|
||||
debug(`Statistics initialized with ${count} emails, largest UID: ${largestUid}`)
|
||||
})
|
||||
|
||||
// Set up timer sync broadcasting after IMAP is ready
|
||||
|
|
|
|||
|
|
@ -172,7 +172,8 @@ class Helper {
|
|||
}
|
||||
|
||||
async getLargestUid(imapService) {
|
||||
return await imapService.getLargestUid();
|
||||
const uid = await imapService.getLargestUid();
|
||||
return uid || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class StatisticsStore {
|
|||
constructor() {
|
||||
// Current totals
|
||||
this.currentCount = 0
|
||||
this.historicalTotal = 0
|
||||
this.largestUid = 0
|
||||
|
||||
// 24-hour rolling data (one entry per minute = 1440 entries)
|
||||
this.hourlyData = []
|
||||
|
|
@ -26,18 +26,27 @@ class StatisticsStore {
|
|||
*/
|
||||
initialize(count) {
|
||||
this.currentCount = count
|
||||
this.historicalTotal = count
|
||||
debug(`Initialized with ${count} emails`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update largest UID (all-time total emails processed)
|
||||
* @param {number} uid - Largest UID from mailbox (0 if no emails)
|
||||
*/
|
||||
updateLargestUid(uid) {
|
||||
if (uid >= 0 && uid > this.largestUid) {
|
||||
this.largestUid = uid
|
||||
debug(`Largest UID updated to ${uid}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record an email received event
|
||||
*/
|
||||
recordReceive() {
|
||||
this.currentCount++
|
||||
this.historicalTotal++
|
||||
this._addDataPoint('receive')
|
||||
debug(`Email received. Current: ${this.currentCount}, Historical: ${this.historicalTotal}`)
|
||||
this._addDataPoint('receive')
|
||||
debug(`Email received. Current: ${this.currentCount}`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,7 +93,7 @@ class StatisticsStore {
|
|||
|
||||
return {
|
||||
currentCount: this.currentCount,
|
||||
historicalTotal: this.historicalTotal,
|
||||
allTimeTotal: this.largestUid,
|
||||
last24Hours: {
|
||||
receives: last24h.receives,
|
||||
deletes: last24h.deletes,
|
||||
|
|
@ -117,7 +126,7 @@ class StatisticsStore {
|
|||
|
||||
entry[type + 's']++
|
||||
|
||||
this._cleanup()
|
||||
this._cleanup()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,13 +7,20 @@ router.get('/', async(req, res) => {
|
|||
try {
|
||||
const config = req.app.get('config')
|
||||
const statisticsStore = req.app.get('statisticsStore')
|
||||
const imapService = req.app.get('imapService')
|
||||
const Helper = require('../../../application/helper')
|
||||
const helper = new Helper()
|
||||
|
||||
// Update largest UID before getting stats (if IMAP is ready)
|
||||
if (imapService) {
|
||||
const largestUid = await helper.getLargestUid(imapService)
|
||||
statisticsStore.updateLargestUid(largestUid)
|
||||
}
|
||||
|
||||
const stats = statisticsStore.getStats()
|
||||
const purgeTime = helper.purgeTimeElemetBuilder()
|
||||
|
||||
debug(`Stats page requested: ${stats.currentCount} current, ${stats.historicalTotal} historical`)
|
||||
debug(`Stats page requested: ${stats.currentCount} current, ${stats.allTimeTotal} all-time total`)
|
||||
|
||||
res.render('stats', {
|
||||
title: `Statistics | ${config.http.branding[0]}`,
|
||||
|
|
@ -34,6 +41,16 @@ router.get('/', async(req, res) => {
|
|||
router.get('/api', async(req, res) => {
|
||||
try {
|
||||
const statisticsStore = req.app.get('statisticsStore')
|
||||
const imapService = req.app.get('imapService')
|
||||
const Helper = require('../../../application/helper')
|
||||
const helper = new Helper()
|
||||
|
||||
// Update largest UID before getting stats (if IMAP is ready)
|
||||
if (imapService) {
|
||||
const largestUid = await helper.getLargestUid(imapService)
|
||||
statisticsStore.updateLargestUid(largestUid)
|
||||
}
|
||||
|
||||
const stats = statisticsStore.getStats()
|
||||
|
||||
res.json(stats)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
<!-- Historical Total -->
|
||||
<div class="stat-card">
|
||||
<div class="stat-value" id="historicalTotal">{{ stats.historicalTotal }}</div>
|
||||
<div class="stat-value" id="historicalTotal">{{ stats.allTimeTotal }}</div>
|
||||
<div class="stat-label">All Time Total</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue