Najjar\NajjarV02 dc42aeb72a
Some checks failed
CI/CD / test-and-build (push) Has been cancelled
CI/CD / deploy (push) Has been cancelled
feat: implement snapshot capture and storage for robot configurations
2026-04-13 18:00:12 +04:00

34 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
export async function POST(request: Request) {
try {
const { paymentIntentId, imageData } = await request.json();
// Validate paymentIntentId format
if (!paymentIntentId || typeof paymentIntentId !== 'string' || !paymentIntentId.startsWith('pi_')) {
return NextResponse.json({ error: 'Invalid paymentIntentId' }, { status: 400 });
}
if (!imageData || typeof imageData !== 'string') {
return NextResponse.json({ error: 'Invalid imageData' }, { status: 400 });
}
// Only accept data URLs (JPEG or PNG)
if (!imageData.startsWith('data:image/jpeg;base64,') && !imageData.startsWith('data:image/png;base64,')) {
return NextResponse.json({ error: 'Invalid image format' }, { status: 400 });
}
await prisma.snapshot.upsert({
where: { paymentIntentId },
create: { paymentIntentId, imageData },
update: { imageData },
});
return NextResponse.json({ success: true });
} catch (err) {
const message = err instanceof Error ? err.message : 'Internal server error';
return NextResponse.json({ error: message }, { status: 500 });
}
}