mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-10 19:39:34 +01:00
Enhances user interface by displaying both the current number of emails and the largest UID seen, offering better visibility into historical mailbox activity. Updates backend logic and view templates to support this change, and improves maintainability by centralizing count formatting.
44 lines
No EOL
1.8 KiB
JavaScript
44 lines
No EOL
1.8 KiB
JavaScript
const express = require('express')
|
|
|
|
const router = new express.Router()
|
|
const config = require('../../../application/config')
|
|
const Helper = require('../../../application/helper')
|
|
const helper = new(Helper)
|
|
const debug = require('debug')('48hr-email:routes')
|
|
|
|
const purgeTime = helper.purgeTimeElemetBuilder()
|
|
|
|
router.get('/:address/:errorCode', async(req, res, next) => {
|
|
try {
|
|
const mailProcessingService = req.app.get('mailProcessingService')
|
|
if (!mailProcessingService) {
|
|
throw new Error('Mail processing service not available')
|
|
}
|
|
debug(`Error page requested: ${req.params.errorCode} for ${req.params.address}`)
|
|
const count = await mailProcessingService.getCount()
|
|
const largestUid = await req.app.locals.imapService.getLargestUid()
|
|
const totalcount = helper.countElementBuilder(count, largestUid)
|
|
const errorCode = parseInt(req.params.errorCode) || 404
|
|
const message = req.query.message || (req.session && req.session.errorMessage) || 'An error occurred'
|
|
|
|
debug(`Rendering error page ${errorCode} with message: ${message}`)
|
|
res.status(errorCode)
|
|
res.render('error', {
|
|
title: `${config.http.branding[0]} | ${errorCode}`,
|
|
purgeTime: purgeTime,
|
|
address: req.params.address,
|
|
count: count,
|
|
totalcount: totalcount,
|
|
message: message,
|
|
status: errorCode,
|
|
branding: config.http.branding
|
|
})
|
|
} catch (error) {
|
|
debug('Error loading error page:', error.message)
|
|
console.error('Error while loading error page', error)
|
|
// For error pages, we should still try to render something basic
|
|
res.status(500).send('Internal Server Error')
|
|
}
|
|
})
|
|
|
|
module.exports = router |