Read-only mirror of the client's existing system as it stood before our work began. Taken from matthijsexpand@149.210.159.152 (TransIP VPS, Lelystad NL) with the client's written permission. Contents: - home-weddingcaketopper/ Next.js app, proxy.py, supabase schema - var-www/ static webroots for all three domains - etc-nginx/ vhost configs (previously unversioned, server-only) Excluded: node_modules (704M, regenerable), .next (17M, regenerable), and env file contents (present on local disk, gitignored — see README). Not our IP. Not covered by the proposal's assignment clause.
16 lines
1.6 KiB
TypeScript
16 lines
1.6 KiB
TypeScript
import { NextResponse } from 'next/server';
|
||
import { supabaseAdmin } from '@/lib/supabase';
|
||
import { STYLES } from '@/lib/types';
|
||
export async function POST(req: Request){
|
||
try{
|
||
const form=await req.formData(); const email=String(form.get('email')||''); const name=String(form.get('name')||''); const style=String(form.get('style')||'');
|
||
if(!email||!name||!STYLES.includes(style as any)) return NextResponse.json({error:'Ongeldige invoer.'},{status:400});
|
||
const files=form.getAll('photos').filter(Boolean) as File[]; if(files.length<3||files.length>6) return NextResponse.json({error:'Upload 3 tot 6 foto’s.'},{status:400});
|
||
const sb=supabaseAdmin();
|
||
const {data:order,error}=await sb.from('orders').insert({email,name,style,product:String(form.get('product')||'bruidspaar-taarttopper'),wedding_date:String(form.get('wedding_date')||''),notes:String(form.get('notes')||''),status:'new',payment_status:'pending'}).select('id').single();
|
||
if(error) throw error;
|
||
const bucket=process.env.SUPABASE_BUCKET || 'order-uploads';
|
||
for(const file of files){ const path=`${order.id}/${crypto.randomUUID()}-${file.name}`; const buffer=Buffer.from(await file.arrayBuffer()); const up=await sb.storage.from(bucket).upload(path, buffer, {contentType:file.type, upsert:false}); if(up.error) throw up.error; const {data:pub}=sb.storage.from(bucket).getPublicUrl(path); await sb.from('uploads').insert({order_id:order.id,image_url:pub.publicUrl,path}); }
|
||
return NextResponse.json({orderId:order.id});
|
||
}catch(e:any){return NextResponse.json({error:e.message||'Serverfout'},{status:500})}
|
||
}
|