feat: API route POST /api/images/upload (TDD)

This commit is contained in:
2026-06-08 17:25:40 +02:00
parent c9422be78e
commit a5ced27e93
2 changed files with 106 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import { NextRequest, NextResponse } from 'next/server'
import { uploadProductImage } from '@/lib/shopify'
export async function POST(req: NextRequest) {
let body: Record<string, unknown>
try {
body = await req.json()
} catch {
return NextResponse.json({ error: 'Corps JSON invalide' }, { status: 400 })
}
const { shopifyProductId, imageBase64, filename } = body
if (!shopifyProductId || typeof shopifyProductId !== 'string') {
return NextResponse.json({ error: 'shopifyProductId requis' }, { status: 400 })
}
if (!imageBase64 || typeof imageBase64 !== 'string') {
return NextResponse.json({ error: 'imageBase64 requis' }, { status: 400 })
}
if (!filename || typeof filename !== 'string') {
return NextResponse.json({ error: 'filename requis' }, { status: 400 })
}
try {
const result = await uploadProductImage(shopifyProductId, imageBase64, filename)
return NextResponse.json(result)
} catch (err) {
const message = err instanceof Error ? err.message : 'Erreur inconnue'
return NextResponse.json({ error: message }, { status: 500 })
}
}