mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 06:41:46 +00:00
Merge pull request #639 from mauriceboe/fix/537-notifications-bugs
fix(notifications): fix SMTP error surfacing, webhook button label, backup timestamp
This commit is contained in:
@@ -1353,7 +1353,7 @@ export default function AdminPage(): React.ReactElement {
|
|||||||
disabled={!smtpValues.admin_webhook_url?.trim()}
|
disabled={!smtpValues.admin_webhook_url?.trim()}
|
||||||
className="px-4 py-2 border border-slate-300 text-slate-700 rounded-lg text-sm font-medium hover:bg-slate-50 transition-colors disabled:opacity-40"
|
className="px-4 py-2 border border-slate-300 text-slate-700 rounded-lg text-sm font-medium hover:bg-slate-50 transition-colors disabled:opacity-40"
|
||||||
>
|
>
|
||||||
{t('admin.smtp.testButton')}
|
{t('admin.notifications.testWebhook')}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export function listBackups(): BackupInfo[] {
|
|||||||
filename,
|
filename,
|
||||||
size: stat.size,
|
size: stat.size,
|
||||||
sizeText: formatSize(stat.size),
|
sizeText: formatSize(stat.size),
|
||||||
created_at: stat.birthtime.toISOString(),
|
created_at: stat.mtime.toISOString(),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||||
|
|||||||
@@ -399,9 +399,24 @@ export async function sendWebhook(url: string, payload: { event: string; title:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function testSmtp(to: string): Promise<{ success: boolean; error?: string }> {
|
export async function testSmtp(to: string): Promise<{ success: boolean; error?: string }> {
|
||||||
|
if (!getSmtpConfig()) return { success: false, error: 'SMTP not configured' };
|
||||||
try {
|
try {
|
||||||
const sent = await sendEmail(to, 'Test Notification', 'This is a test email from TREK. If you received this, your SMTP configuration is working correctly.');
|
const config = getSmtpConfig()!;
|
||||||
return sent ? { success: true } : { success: false, error: 'SMTP not configured' };
|
const skipTls = process.env.SMTP_SKIP_TLS_VERIFY === 'true' || getAppSetting('smtp_skip_tls_verify') === 'true';
|
||||||
|
const transporter = nodemailer.createTransport({
|
||||||
|
host: config.host,
|
||||||
|
port: config.port,
|
||||||
|
secure: config.secure,
|
||||||
|
auth: config.user ? { user: config.user, pass: config.pass } : undefined,
|
||||||
|
...(skipTls ? { tls: { rejectUnauthorized: false } } : {}),
|
||||||
|
});
|
||||||
|
await transporter.sendMail({
|
||||||
|
from: config.from,
|
||||||
|
to,
|
||||||
|
subject: 'TREK — Test Notification',
|
||||||
|
text: 'This is a test email from TREK. If you received this, your SMTP configuration is working correctly.',
|
||||||
|
});
|
||||||
|
return { success: true };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { success: false, error: err instanceof Error ? err.message : 'Unknown error' };
|
return { success: false, error: err instanceof Error ? err.message : 'Unknown error' };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ describe('BACKUP-041 listBackups', () => {
|
|||||||
fsMock.readdirSync.mockReturnValue(['backup-2026-01-01T00-00-00.zip']);
|
fsMock.readdirSync.mockReturnValue(['backup-2026-01-01T00-00-00.zip']);
|
||||||
fsMock.statSync.mockReturnValue({
|
fsMock.statSync.mockReturnValue({
|
||||||
size: 1024,
|
size: 1024,
|
||||||
birthtime: new Date('2026-01-01T00:00:00Z'),
|
mtime: new Date('2026-01-01T00:00:00Z'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = listBackups();
|
const result = listBackups();
|
||||||
@@ -599,9 +599,9 @@ describe('BACKUP-041 listBackups', () => {
|
|||||||
]);
|
]);
|
||||||
fsMock.statSync.mockImplementation((p: string) => {
|
fsMock.statSync.mockImplementation((p: string) => {
|
||||||
if (String(p).includes('2026-01-01')) {
|
if (String(p).includes('2026-01-01')) {
|
||||||
return { size: 512, birthtime: new Date('2026-01-01T00:00:00Z') };
|
return { size: 512, mtime: new Date('2026-01-01T00:00:00Z') };
|
||||||
}
|
}
|
||||||
return { size: 2048, birthtime: new Date('2026-06-01T00:00:00Z') };
|
return { size: 2048, mtime: new Date('2026-06-01T00:00:00Z') };
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = listBackups();
|
const result = listBackups();
|
||||||
@@ -619,7 +619,7 @@ describe('BACKUP-041 listBackups', () => {
|
|||||||
]);
|
]);
|
||||||
fsMock.statSync.mockReturnValue({
|
fsMock.statSync.mockReturnValue({
|
||||||
size: 1024,
|
size: 1024,
|
||||||
birthtime: new Date('2026-01-01T00:00:00Z'),
|
mtime: new Date('2026-01-01T00:00:00Z'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = listBackups();
|
const result = listBackups();
|
||||||
|
|||||||
Reference in New Issue
Block a user