mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2025-12-14 05:46:33 +01:00
We are balls-deep in errors we should never see.... I wanna leave.
This commit is contained in:
parent
f68dfe0da2
commit
2902d0fcc5
2 changed files with 65 additions and 8 deletions
|
|
@ -116,13 +116,42 @@ router.get(
|
|||
async(req, res, next) => {
|
||||
try {
|
||||
const mailProcessingService = req.app.get('mailProcessingService')
|
||||
const uid = parseInt(req.params.uid, 10)
|
||||
const count = await mailProcessingService.getCount()
|
||||
|
||||
// Validate UID is a valid integer
|
||||
if (isNaN(uid) || uid <= 0) {
|
||||
return res.render(
|
||||
'error', {
|
||||
purgeTime: purgeTime,
|
||||
address: req.params.address,
|
||||
count: count,
|
||||
message: 'Invalid/Malformed UID provided.',
|
||||
branding: config.http.branding,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const mail = await mailProcessingService.getOneFullMail(
|
||||
req.params.address,
|
||||
req.params.uid
|
||||
uid
|
||||
)
|
||||
|
||||
if (!mail || !mail.attachments) {
|
||||
return res.render(
|
||||
'error', {
|
||||
purgeTime: purgeTime,
|
||||
address: req.params.address,
|
||||
count: count,
|
||||
message: 'This email could not be found. It either does not exist or has been deleted from our servers!',
|
||||
branding: config.http.branding,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var index = mail.attachments.findIndex(attachment => attachment.checksum === req.params.checksum);
|
||||
const attachment = mail.attachments[index];
|
||||
const count = await mailProcessingService.getCount()
|
||||
|
||||
if (attachment) {
|
||||
try {
|
||||
res.set('Content-Disposition', `attachment; filename=${attachment.filename}`);
|
||||
|
|
@ -132,9 +161,10 @@ router.get(
|
|||
} catch (error) {
|
||||
console.error('Error while fetching attachment', error);
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
res.render(
|
||||
return res.render(
|
||||
'error', {
|
||||
purgeTime: purgeTime,
|
||||
address: req.params.address,
|
||||
|
|
@ -144,9 +174,8 @@ router.get(
|
|||
}
|
||||
)
|
||||
}
|
||||
res.redirect(`/inbox/${req.params.address}`)
|
||||
} catch (error) {
|
||||
console.error('Error while deleting email', error)
|
||||
console.error('Error while fetching attachment', error)
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
|
@ -160,10 +189,25 @@ router.get(
|
|||
async(req, res, next) => {
|
||||
try {
|
||||
const mailProcessingService = req.app.get('mailProcessingService')
|
||||
const uid = parseInt(req.params.uid, 10)
|
||||
const count = await mailProcessingService.getCount()
|
||||
|
||||
// Validate UID is a valid integer
|
||||
if (isNaN(uid) || uid <= 0) {
|
||||
return res.render(
|
||||
'error', {
|
||||
purgeTime: purgeTime,
|
||||
address: req.params.address,
|
||||
count: count,
|
||||
message: 'Invalid/Malformed UID provided.',
|
||||
branding: config.http.branding,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
mail = await mailProcessingService.getOneFullMail(
|
||||
req.params.address,
|
||||
req.params.uid,
|
||||
uid,
|
||||
true
|
||||
)
|
||||
if (mail) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ const inboxRouter = require('./routes/inbox')
|
|||
const loginRouter = require('./routes/login')
|
||||
const { sanitizeHtmlTwigFilter } = require('./views/twig-filters')
|
||||
|
||||
const Helper = require('../../application/helper')
|
||||
const helper = new(Helper)
|
||||
const purgeTime = helper.purgeTimeElemetBuilder()
|
||||
|
||||
// Init express middleware
|
||||
const app = express()
|
||||
app.use(helmet())
|
||||
|
|
@ -66,14 +70,23 @@ app.use((req, res, next) => {
|
|||
})
|
||||
|
||||
// Error handler
|
||||
app.use((err, req, res, _next) => {
|
||||
app.use(async(err, req, res, _next) => {
|
||||
const mailProcessingService = req.app.get('mailProcessingService')
|
||||
const count = await mailProcessingService.getCount()
|
||||
|
||||
// Set locals, only providing error in development
|
||||
res.locals.message = err.message
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
||||
|
||||
// Render the error page
|
||||
res.status(err.status || 500)
|
||||
res.render('error')
|
||||
res.render('error', {
|
||||
purgeTime: purgeTime,
|
||||
address: req.params.address,
|
||||
count: count,
|
||||
branding: config.http.branding
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue