From e263e7f25cc41e2d37f824e531ed6afe49d507d5 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 6 May 2026 12:50:07 +0200 Subject: [PATCH] feat(contact): add local jsonl backup for fail-safe lead retention --- app/actions/contact.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/actions/contact.ts b/app/actions/contact.ts index 4c0dab57..54e48321 100644 --- a/app/actions/contact.ts +++ b/app/actions/contact.ts @@ -45,6 +45,28 @@ export async function sendContactFormAction(formData: FormData) { email, }); + // 1.5. Simple Fail-Safe Backup to Disk + // To ensure leads are never lost if email fails or Gotify is down, we append them to a local JSON Lines file. + try { + const fs = await import('fs'); + const path = await import('path'); + const backupDir = path.join(process.cwd(), '.data'); + if (!fs.existsSync(backupDir)) fs.mkdirSync(backupDir, { recursive: true }); + + const backupFile = path.join(backupDir, 'leads-backup.jsonl'); + const leadData = { + timestamp: new Date().toISOString(), + name, + email, + productName, + message, + }; + fs.appendFileSync(backupFile, JSON.stringify(leadData) + '\\n'); + logger.info('Successfully saved lead to local backup file', { backupFile }); + } catch (backupError) { + logger.error('Failed to write to local leads backup', { error: String(backupError) }); + } + // 2. Send Emails logger.info('Sending branded emails', { email, productName });