From c76f66c0fdcb1395446e09437923f3a62709183a Mon Sep 17 00:00:00 2001 From: will Date: Thu, 2 Apr 2026 23:29:59 +0100 Subject: [PATCH] cloudlfare --- .env.local | 4 +- app/api/contact/route.ts | 2 +- app/api/gitea/readme/route.ts | 5 +- components/Contact.tsx | 147 +++++++++++++++++++++++++++++++--- package-lock.json | 11 +++ package.json | 1 + 6 files changed, 154 insertions(+), 16 deletions(-) diff --git a/.env.local b/.env.local index 2fd73f2..7e5f2e9 100644 --- a/.env.local +++ b/.env.local @@ -2,5 +2,5 @@ GITEA_URL=https://git.williammarch.xyz GITEA_USERNAME=m0dus -NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAACzsXdlmXw00QAai -TURNSTILE_SECRET_KEY=0x4AAAAAACzsXeYTwCALD_kLJqaZESctCUo +NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAACzsqWrzBq00jrzS +TURNSTILE_SECRET_KEY=0x4AAAAAACzsqSwNTHM_tj3EG-q_Nwlxtm4 diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index bbf115a..347ca6a 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -89,7 +89,7 @@ export async function POST(req: Request) { // Send email via local sendmail (Postfix/Sendmail/Exim) await transporter.sendMail({ from: 'William March ', - to: 'your-real-inbox@example.com', // TODO: change to your inbox + to: 'qemuguest@protonmail.com', replyTo: email, subject: `New message from ${name} via williammarch.xyz`, text: `From: ${name} <${email}>\n\n${message}`, diff --git a/app/api/gitea/readme/route.ts b/app/api/gitea/readme/route.ts index 4ec777d..54b59f5 100644 --- a/app/api/gitea/readme/route.ts +++ b/app/api/gitea/readme/route.ts @@ -32,7 +32,10 @@ export async function GET(req: NextRequest) { } const md = await res.text(); - const html = marked.parse(md || ''); + + // marked.parse can return string | Promise, + // so we call it in async mode and await the result. + const html = await marked.parse(md || '', { async: true }); return new NextResponse(html, { status: 200, diff --git a/components/Contact.tsx b/components/Contact.tsx index 8744ee1..1529eba 100644 --- a/components/Contact.tsx +++ b/components/Contact.tsx @@ -31,6 +31,7 @@ export default function Contact() { const [turnstileToken, setTurnstileToken] = useState(''); const widgetIdRef = useRef(null); const turnstileRef = useRef(null); + const startedAtRef = useRef(Date.now()); useEffect(() => { if (!TURNSTILE_SITE_KEY) { @@ -48,6 +49,7 @@ export default function Contact() { theme: 'dark', callback: token => { setTurnstileToken(token); + setErrorMessage(''); }, 'expired-callback': () => { setTurnstileToken(''); @@ -85,7 +87,7 @@ export default function Contact() { name: String(fd.get('name') || '').trim(), email: String(fd.get('email') || '').trim(), message: String(fd.get('message') || '').trim(), - company: String(fd.get('company') || '').trim(), // honeypot + company: String(fd.get('company') || '').trim(), turnstileToken, formStartedAt: String(fd.get('formStartedAt') || ''), }; @@ -117,7 +119,9 @@ export default function Contact() { setStatus('sent'); form.reset(); + startedAtRef.current = Date.now(); setTurnstileToken(''); + if (window.turnstile && widgetIdRef.current) { window.turnstile.reset(widgetIdRef.current); } @@ -126,10 +130,11 @@ export default function Contact() { setErrorMessage( err instanceof Error ? err.message : 'Something went wrong.', ); - } finally { - if (status !== 'sent') { - setStatus(prev => (prev === 'sent' ? 'sent' : 'idle')); + + if (window.turnstile && widgetIdRef.current) { + window.turnstile.reset(widgetIdRef.current); } + setTurnstileToken(''); } } @@ -141,6 +146,7 @@ export default function Contact() { >
Get in touch +

+ {/* Left side contact cards */} + {/* Form */}
- + {/* Honeypot */}
- {/* fields unchanged */} - {/* ... */} +
+ + + +
+ +