This commit is contained in:
root
2025-12-21 17:36:44 +01:00
parent bb1c5b43d6
commit 8a0835c564
15 changed files with 1124 additions and 193 deletions

View File

@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from 'next/server'
import pool from '@/lib/db'
// GET /api/drops/images?drop_id=X - Get all images for a drop
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams
const dropId = searchParams.get('drop_id')
if (!dropId) {
return NextResponse.json(
{ error: 'drop_id parameter is required' },
{ status: 400 }
)
}
const [rows] = await pool.execute(
'SELECT id, image_url, display_order FROM drop_images WHERE drop_id = ? ORDER BY display_order ASC LIMIT 4',
[dropId]
)
return NextResponse.json(rows)
} catch (error) {
console.error('Error fetching drop images:', error)
return NextResponse.json(
{ error: 'Failed to fetch drop images' },
{ status: 500 }
)
}
}
// POST /api/drops/images - Add images to a drop
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { drop_id, image_urls } = body
if (!drop_id || !image_urls || !Array.isArray(image_urls)) {
return NextResponse.json(
{ error: 'drop_id and image_urls array are required' },
{ status: 400 }
)
}
if (image_urls.length > 4) {
return NextResponse.json(
{ error: 'Maximum 4 images allowed per drop' },
{ status: 400 }
)
}
// Delete existing images for this drop
await pool.execute('DELETE FROM drop_images WHERE drop_id = ?', [drop_id])
// Insert new images
for (let i = 0; i < image_urls.length; i++) {
await pool.execute(
'INSERT INTO drop_images (drop_id, image_url, display_order) VALUES (?, ?, ?)',
[drop_id, image_urls[i], i]
)
}
return NextResponse.json({ success: true })
} catch (error) {
console.error('Error saving drop images:', error)
return NextResponse.json(
{ error: 'Failed to save drop images' },
{ status: 500 }
)
}
}