48hr.email/infrastructure/web/template-context.js
ClaraCrazy 345935f8b9
[Feat]: Update Config structure, add more feature flags, fix 302s
This is what makes a project a "Clara project"... going the extra mile for customizability <3
2026-01-05 04:50:53 +01:00

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()