import { getCustomerUser } from '@/app/lib/lumen-auth'; import { StudioError } from '@/app/lib/studio-media'; import { emailSignupReady } from '@/app/lib/studio-config'; import { createPrintQuote, parsePrintSelection, PRINT_HEADERS, printArtwork, printEnabled, printError, readPrintForm, requirePrintCustomer } from '../protocol'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; export async function GET() { const enabled = printEnabled(); const signedIn = Boolean(await getCustomerUser().catch(() => null)); return Response.json({ enabled, signedIn, signupAvailable: await emailSignupReady(enabled) }, { headers: PRINT_HEADERS }); } export async function POST(req: Request) { try { const user = await requirePrintCustomer(req); const form = await readPrintForm(req, ['image', 'selection']); const raw = form.get('selection'); let selection: unknown; try { if (typeof raw !== 'string' || raw.length > 1024) throw new Error('invalid selection'); selection = JSON.parse(raw); } catch { throw new StudioError('invalid_selection', 400, 'Choose an available print size, frame and finish.'); } const parsed = parsePrintSelection(selection); return Response.json(createPrintQuote(user.id, parsed, await printArtwork(form.get('image'), parsed)), { headers: PRINT_HEADERS }); } catch (error) { return printError(error); } }