[Fix]: Fix social-media stats embed

The new lazyloading broke it
This commit is contained in:
ClaraCrazy 2026-01-05 06:35:04 +01:00
parent 8d7cc06b5e
commit 6ba3ccf415
No known key found for this signature in database
GPG key ID: EBBC896ACB497011
2 changed files with 34 additions and 4 deletions

View file

@ -19,6 +19,35 @@ router.get('/', async(req, res) => {
const branding = config.http.features.branding || ['48hr.email', 'Service', 'https://example.com'] const branding = config.http.features.branding || ['48hr.email', 'Service', 'https://example.com']
// Get minimal stats for meta tags (non-blocking, quick)
const statisticsStore = req.app.get('statisticsStore')
const mailProcessingService = req.app.get('mailProcessingService')
let metaStats = {
currentCount: 0,
allTimeTotal: 0
}
if (statisticsStore) {
try {
const quickStats = statisticsStore.getEnhancedStats()
metaStats = {
currentCount: quickStats.currentCount || 0,
allTimeTotal: quickStats.allTimeTotal || 0
}
} catch (error) {
debug(`Error getting meta stats: ${error.message}`)
}
}
// Fallback to mailProcessingService if stats are still 0
if (metaStats.currentCount === 0 && mailProcessingService) {
try {
metaStats.currentCount = mailProcessingService.getCount() || 0
} catch (error) {
debug(`Error getting count from mailProcessingService: ${error.message}`)
}
}
// Return page with placeholder data immediately - real data loads via JS // Return page with placeholder data immediately - real data loads via JS
const placeholderStats = { const placeholderStats = {
currentCount: '...', currentCount: '...',
@ -49,6 +78,7 @@ router.get('/', async(req, res) => {
res.render('stats', templateContext.build(req, { res.render('stats', templateContext.build(req, {
title: `Statistics | ${branding[0]}`, title: `Statistics | ${branding[0]}`,
stats: placeholderStats, stats: placeholderStats,
metaStats: metaStats,
lazyLoad: true lazyLoad: true
})) }))
} catch (error) { } catch (error) {

View file

@ -2,21 +2,21 @@
{% block metaTags %} {% block metaTags %}
<!-- Statistics Page - Custom Meta Tags --> <!-- Statistics Page - Custom Meta Tags -->
<meta name="description" content="Live email statistics: {{ stats.currentCount }} emails in system, {{ stats.allTimeTotal }} processed all-time. Real-time monitoring, historical patterns, and predictions over {{ purgeTime|striptags }}."> <meta name="description" content="Live email statistics: {{ metaStats.currentCount }} emails in system, {{ metaStats.allTimeTotal }} processed all-time. Real-time monitoring, historical patterns, and predictions over {{ purgeTimeRaw | readablePurgeTime }}.">
<!-- Open Graph / Facebook --> <!-- Open Graph / Facebook -->
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:url" content="https://48hr.email/stats"> <meta property="og:url" content="https://48hr.email/stats">
<meta property="og:title" content="Email Statistics - {{ branding.0 }}"> <meta property="og:title" content="Email Statistics - {{ branding.0 }}">
<meta property="og:description" content="{{ stats.currentCount }} emails in system | {{ stats.allTimeTotal }} all-time total | Real-time monitoring and predictions"> <meta property="og:description" content="{{ metaStats.currentCount }} emails in system | {{ metaStats.allTimeTotal }} all-time total | Real-time monitoring and predictions">
<meta property="og:image" content="https://48hr.email/images/logo.png"> <meta property="og:image" content="https://48hr.email/images/logo.png">
<meta property="og:site_name" content="{{ branding.0 }}"> <meta property="og:site_name" content="{{ branding.0 }}">
<!-- Twitter Card --> <!-- Twitter Card -->
<meta name="twitter:card" content="summary"> <meta name="twitter:card" content="summary">
<meta name="twitter:url" content="https://48hr.email/stats"> <meta name="twitter:url" content="https://48hr.email/stats">
<meta name="twitter:title" content="Email Statistics - {{ branding.0 }}"> <meta name="twitter::title" content="Email Statistics - {{ branding.0 }}">
<meta name="twitter:description" content="{{ stats.currentCount }} emails | {{ stats.allTimeTotal }} all-time | Live monitoring"> <meta name="twitter:description" content="{{ metaStats.currentCount }} emails | {{ metaStats.allTimeTotal }} all-time | Live monitoring">
<meta name="twitter:image" content="https://48hr.email/images/logo.png"> <meta name="twitter:image" content="https://48hr.email/images/logo.png">
{% endblock %} {% endblock %}