mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-09 11:19:36 +01:00
This is what makes a project a "Clara project"... going the extra mile for customizability <3
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const config = require('../../application/config')
|
|
const Helper = require('../../application/helper')
|
|
|
|
/**
|
|
* Template Context Builder
|
|
* Generates common variables for all template renders
|
|
*/
|
|
class TemplateContext {
|
|
constructor() {
|
|
this.helper = new Helper()
|
|
this.purgeTime = this.helper.purgeTimeElemetBuilder()
|
|
}
|
|
|
|
/**
|
|
* Get base context that should be available in all templates
|
|
* @param {Object} req - Express request object
|
|
* @returns {Object} Base template context
|
|
*/
|
|
getBaseContext(req) {
|
|
return {
|
|
// Config values
|
|
config: config,
|
|
branding: config.http.features.branding || ['48hr.email', 'Service', 'https://example.com'],
|
|
purgeTime: this.purgeTime,
|
|
purgeTimeRaw: config.email.purgeTime,
|
|
|
|
// Feature flags
|
|
authEnabled: config.user.authEnabled,
|
|
statisticsEnabled: config.http.features.statistics,
|
|
smtpEnabled: config.email.features.smtp,
|
|
showInfoSection: config.http.features.infoSection,
|
|
|
|
// User session
|
|
currentUser: req.session && req.session.username ? req.session.username : null,
|
|
|
|
// Common data
|
|
domains: this.helper.getDomains(),
|
|
example: config.email.examples.account
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Merge base context with page-specific data
|
|
* @param {Object} req - Express request object
|
|
* @param {Object} pageData - Page-specific template data
|
|
* @returns {Object} Complete template context
|
|
*/
|
|
build(req, pageData = {}) {
|
|
return {
|
|
...this.getBaseContext(req),
|
|
...pageData
|
|
}
|
|
}
|
|
}
|
|
|
|
// Export singleton instance
|
|
module.exports = new TemplateContext()
|