Hub 2.10.0: emails laid out as Events' and Accounts'; FastPanel ^~ /api/
- src/utils/emailLayout.js: one layout for every Hub email (Cross Code header with the logo, heading, button with the link under it, notes, tables, job steps, code blocks, footer), HTML and plain text from the same blocks, everything escaped. mail.sendMail attaches the logo. - Every email moved onto it: job reports, alerts, update requests, the SMTP test, notices, and all emails to site admins. Billing keeps its own. - The FastPanel email and the install page give the backend as nginx config with location ^~ /api/ (FastPanel's static-file rule took /api/...png). - Proxy done checks /api/proxy-check.png doesn't reach the frontend. - deployment.md: ^~ for the Hub's own /api/ too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ const prisma = require('../config/db');
|
||||
const { encrypt, decrypt } = require('./crypto');
|
||||
const { getSettings } = require('./settings');
|
||||
const { sendMail } = require('./mail');
|
||||
const { render } = require('./emailLayout');
|
||||
|
||||
const JOIN_TOKEN_MINUTES = 60;
|
||||
const POLL_SECONDS = 30;
|
||||
@@ -230,22 +231,27 @@ async function runServerAlerts(now = new Date()) {
|
||||
for (const p of current) {
|
||||
if (open.has(p.type)) continue;
|
||||
await prisma.serverAlert.create({ data: { serverId: server.id, type: p.type, level: p.level, message: p.message, createdAt: now } });
|
||||
opened.push(`• ${server.name}: ${p.message}`);
|
||||
opened.push({ level: p.level, text: `${server.name}: ${p.message}` });
|
||||
}
|
||||
const types = new Set(current.map(p => p.type));
|
||||
for (const [type, a] of open) {
|
||||
if (types.has(type)) continue;
|
||||
await prisma.serverAlert.update({ where: { id: a.id }, data: { resolvedAt: now } });
|
||||
cleared.push(`• ${server.name}: cleared: ${a.message}`);
|
||||
cleared.push(`${server.name}: ${a.message}`);
|
||||
}
|
||||
}
|
||||
const lines = [...opened, ...cleared];
|
||||
if (lines.length && settings.alert_email) {
|
||||
await sendMail({
|
||||
to: settings.alert_email,
|
||||
subject: `Cross Code Hub: ${opened.length ? `${opened.length} server alert${opened.length === 1 ? '' : 's'}` : 'server alerts cleared'}`,
|
||||
text: `${lines.join('\n')}\n\n${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/servers`,
|
||||
}).catch(e => console.warn('[servers] alert email failed:', e?.message));
|
||||
if ((opened.length || cleared.length) && settings.alert_email) {
|
||||
const subject = opened.length ? `${opened.length} server alert${opened.length === 1 ? '' : 's'}` : 'server alerts cleared';
|
||||
const email = render({
|
||||
heading: opened.length ? `${opened.length} server alert${opened.length === 1 ? '' : 's'}` : 'Server alerts cleared',
|
||||
blocks: [
|
||||
...opened.map(o => ({ note: { kind: o.level === 'critical' ? 'danger' : 'warning', text: o.text } })),
|
||||
cleared.length ? { note: { kind: 'success', title: 'Cleared', text: cleared.join('\n') } } : null,
|
||||
{ button: { label: 'Open Servers', url: `${(process.env.FRONTEND_URL || '').replace(/\/$/, '')}/servers` } },
|
||||
],
|
||||
footer: 'Sent by the Cross Code Hub to the alert address in Settings.',
|
||||
});
|
||||
await sendMail({ to: settings.alert_email, subject: `Cross Code Hub: ${subject}`, ...email }).catch(e => console.warn('[servers] alert email failed:', e?.message));
|
||||
}
|
||||
return { opened: opened.length, cleared: cleared.length };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user