Fix image handling to support category, room_id, and location_target fields

This commit is contained in:
2026-06-28 06:35:38 -05:00
parent 6b13a35fbe
commit a47f54d22b
2 changed files with 5 additions and 4 deletions
+4 -4
View File
@@ -5,7 +5,7 @@ import { db } from '@/lib/db';
export async function GET() {
try {
await requireRole('admin');
const { rows } = await db.query('SELECT id, filename, uploaded_at FROM images ORDER BY uploaded_at DESC');
const { rows } = await db.query('SELECT id, filename, category, room_id, location_target, uploaded_at FROM images ORDER BY uploaded_at DESC');
return NextResponse.json({ images: rows, count: rows.length });
} catch (error) {
if ((error as Error).message === 'Unauthorized') {
@@ -20,15 +20,15 @@ export async function POST(request: NextRequest) {
try {
await requireRole('admin');
const body = await request.json();
const { filename, data } = body;
const { filename, data, category, room_id, location_target } = body;
if (!filename || !data) {
return NextResponse.json({ error: 'Missing filename or data' }, { status: 400 });
}
const { rows } = await db.query(
'INSERT INTO images (filename, data) VALUES ($1, $2) RETURNING id, filename, uploaded_at',
[filename, data]
'INSERT INTO images (filename, data, category, room_id, location_target) VALUES ($1, $2, $3, $4, $5) RETURNING id, filename, category, room_id, location_target, uploaded_at',
[filename, data, category || 'other', room_id || null, location_target || 'gallery']
);
return NextResponse.json({ image: rows[0] });
+1
View File
@@ -22,6 +22,7 @@ export async function initSchema() {
data TEXT NOT NULL,
category VARCHAR(100) DEFAULT 'other',
room_id INTEGER REFERENCES rooms(id) ON DELETE SET NULL,
location_target VARCHAR(100) DEFAULT 'gallery',
uploaded_at TIMESTAMP DEFAULT NOW()
);
`);