Update conversion function and footer
- Conversion function updates: - Enabling conversion now rounds to the nearest max. value where `i > 1`, and if rounding was needed it will create a Tooltip displaying the config value on hover. - If rounding wasnt needed, or conversion is disabled in the config then no tooltip will be created, to avoid confusion. - Updated footer: - Created new function called footerbuilder() - The config value is now always underlined and italic to make it more obvious you can (if rounded) "interact" with it.pull/16/head
parent
d992ec2470
commit
0770ebdfc2
|
@ -1,13 +1,13 @@
|
|||
const config = {
|
||||
email: {
|
||||
email: { // Email configuration
|
||||
domains: process.env.EMAIL_DOMAINS, // List object of domains
|
||||
purgeTime: process.env.EMAIL_PURGE_TIME || {
|
||||
time: 48, // Time value to purge
|
||||
time: 48, // Time value for when to purge
|
||||
unit: 'hours', // minutes, hours, days
|
||||
convert: true, // Convert to highest sensible unit
|
||||
convert: true, // Convert to highest sensible unit (and round)
|
||||
}
|
||||
},
|
||||
imap: {
|
||||
imap: { // IMAP configuration
|
||||
user: process.env.IMAP_USER, // imap user
|
||||
password: process.env.IMAP_PASSWORD, // imap password
|
||||
host: process.env.IMAP_SERVER, // imap server
|
||||
|
@ -16,12 +16,12 @@ const config = {
|
|||
authTimeout: process.env.IMAP_AUTHTIMEOUT || 3000, // timeout for auth
|
||||
refreshIntervalSeconds: process.env.IMAP_REFRESH_INTERVAL_SECONDS || 60 // refresh interval
|
||||
},
|
||||
http: {
|
||||
port: normalizePort(process.env.HTTP_PORT || 3000), // http port
|
||||
http: { // HTTP configuration
|
||||
port: normalizePort(process.env.HTTP_PORT || 3000), // http port to listen on
|
||||
branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], // branding
|
||||
examples: process.env.HTTP_EXAMPLES || {
|
||||
email: "example@48hr.email", // example email
|
||||
ids: [1, 2, 3] // example ids
|
||||
examples: process.env.HTTP_EXAMPLES || { // Examples to use to demonstrate the service
|
||||
email: "example@48hr.email", // example email to keep clean, besides the IDs specified below
|
||||
ids: [1, 2, 3] // example ids to keep
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -29,30 +29,61 @@ class Helper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert time to highest possible unit (minutes, hours, days) where `time > 2` and `Number.isSafeInteger(time)` (whole number)
|
||||
* Convert time to highest possible unit (minutes, hours, days) where `time > 1` and `Number.isSafeInteger(time)` (whole number)
|
||||
* @param {Number} time
|
||||
* @param {String} unit
|
||||
* @returns {String}
|
||||
*/
|
||||
convertUp(time, unit) {
|
||||
convertAndRound(time, unit) {
|
||||
let convertedTime = time;
|
||||
let convertedUnit = unit;
|
||||
let rounded = false;
|
||||
|
||||
if (convertedUnit === 'minutes') {
|
||||
if (convertedTime > 120 && Number.isSafeInteger(convertedTime / 60)) {
|
||||
convertedTime = convertedTime / 60;
|
||||
if (convertedTime > 60) {
|
||||
convertedTime = convertedTime / 60
|
||||
convertedUnit = 'hours';
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
if (convertedUnit === 'hours') {
|
||||
if (convertedTime > 48 && Number.isSafeInteger(convertedTime / 24)) {
|
||||
if (convertedTime > 24) {
|
||||
convertedTime = convertedTime / 24;
|
||||
convertedUnit = 'days';
|
||||
}
|
||||
}
|
||||
|
||||
if (!convertedTime == Number.isSafeInteger(convertedTime)) {
|
||||
convertedTime = Math.round(convertedTime);
|
||||
rounded = true;
|
||||
}
|
||||
|
||||
if (rounded) {
|
||||
convertedTime = `~${convertedTime}`;
|
||||
}
|
||||
|
||||
return `${convertedTime} ${convertedUnit}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a purgeTime html element for the page to keep the clutter outside of the twig template
|
||||
* @returns {String}
|
||||
*/
|
||||
purgeTimeElemetBuilder() {
|
||||
let time = `${config.email.purgeTime.time} ${config.email.purgeTime.unit}`
|
||||
let Tooltip = ''
|
||||
if (config.email.purgeTime.convert) {
|
||||
time = this.convertAndRound(config.email.purgeTime.time, config.email.purgeTime.unit)
|
||||
if (time !== `${config.email.purgeTime.time} ${config.email.purgeTime.unit}`) {
|
||||
Tooltip = `Config: ${config.email.purgeTime.time} ${config.email.purgeTime.unit}`
|
||||
}
|
||||
}
|
||||
|
||||
const footer = `<label title="${Tooltip}">
|
||||
<h4 style="display: inline;"><u><i>${time}</i></u></h4>
|
||||
</Label>`
|
||||
|
||||
return footer
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Helper
|
||||
|
|
|
@ -140,3 +140,7 @@ input, textarea, select, select:active, select:focus, select:hover {
|
|||
width: 80%;
|
||||
padding-left:10%
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
const express = require('express')
|
||||
|
||||
const router = new express.Router()
|
||||
const express = require('express')
|
||||
const {param} = require('express-validator')
|
||||
|
||||
const config = require('../../../application/config')
|
||||
const Helper = require('../../../application/helper')
|
||||
const helper = new(Helper)
|
||||
|
||||
const purgeTime = config.email.purgeTime.convert ? helper.convertUp(config.email.purgeTime.time, config.email.purgeTime.unit)
|
||||
: config.email.purgeTime.time +` ${config.email.purgeTime.unit}`;
|
||||
const purgeTime = helper.purgeTimeElemetBuilder()
|
||||
|
||||
const sanitizeAddress = param('address').customSanitizer(
|
||||
(value, {req}) => {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
const express = require('express')
|
||||
|
||||
const router = new express.Router()
|
||||
const randomWord = require('random-word')
|
||||
const express = require('express')
|
||||
const {check, validationResult} = require('express-validator')
|
||||
|
||||
const randomWord = require('random-word')
|
||||
const config = require('../../../application/config')
|
||||
const Helper = require('../../../application/helper')
|
||||
const helper = new(Helper)
|
||||
|
||||
const purgeTime = config.email.purgeTime.convert ? helper.convertUp(config.email.purgeTime.time, config.email.purgeTime.unit)
|
||||
: config.email.purgeTime.time +` ${config.email.purgeTime.unit}`;
|
||||
const purgeTime = helper.purgeTimeElemetBuilder()
|
||||
|
||||
router.get('/', (req, res, _next) => {
|
||||
res.render('login', {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
{% block footer %}
|
||||
<section class="container footer">
|
||||
<hr>
|
||||
<h4>{{ branding[0] }} offered by <a href="{{ branding[2] }}" style="text-decoration:underline" target="_blank">{{ branding[1] }}</a> | All Emails will be deleted after {{ purgeTime }} | This project is <a href="https://github.com/crazyco-xyz/48hr.email" style="text-decoration:underline" target="_blank">open-source ♥</a></h4>
|
||||
<h4>{{ branding[0] }} offered by <a href="{{ branding[2] }}" style="text-decoration:underline" target="_blank">{{ branding[1] }}</a> | All Emails will be deleted after {{ purgeTime | raw }} | This project is <a href="https://github.com/crazyco-xyz/48hr.email" style="text-decoration:underline" target="_blank">open-source ♥</a></h4>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue