fix: image upload returns correct data structure for all editors

This commit is contained in:
2026-06-28 23:18:27 -05:00
parent 6b0db0e3cf
commit abf46b9075
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -744,7 +744,7 @@ function SocialEditor({ event, setEvent, images, onSave, onCancel }: any) {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: f.name, data: b64, category: 'social', room_id: null, location_target: 'social' }),
});
if (r.ok) { const d = await r.json(); newPhotos.push(d.data); }
if (r.ok) { const d = await r.json(); newPhotos.push(d.data.data); }
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
}
setLocalPhotos(prev => [...prev, ...newPhotos]);
@@ -856,7 +856,7 @@ function RoomEditor({ room, setRoom, images, onSave, onCancel }: any) {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: f.name, data: b64, category: 'rooms', room_id: r.id || null, location_target: `room-${r.id || 'new'}` }),
});
if (res.ok) { const d = await res.json(); newPhotos.push(d.data); }
if (res.ok) { const d = await res.json(); newPhotos.push(d.data.data); }
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
}
setLocalPhotos(prev => [...prev, ...newPhotos]);
@@ -1192,7 +1192,7 @@ function PlaceEditor({ place, setPlace, images, onSave, onCancel }: any) {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: f.name, data: b64, category: 'landscape', room_id: null, location_target: `place-${p.id || 'new'}` }),
});
if (res.ok) { const d = await res.json(); newPhotos.push(d.data); }
if (res.ok) { const d = await res.json(); newPhotos.push(d.data.data); }
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
}
setLocalPhotos(prev => [...prev, ...newPhotos]);
@@ -1310,7 +1310,7 @@ function BrandSection({ images, onToast }: { images: Image[]; onToast: (m: strin
});
if (res.ok) {
const d = await res.json();
setConfig(prev => ({ ...prev, [key]: d.data }));
setConfig(prev => ({ ...prev, [key]: d.data.data }));
onToast('Image uploaded!', 'success');
}
} catch { onToast('Upload failed', 'error'); }
+1 -1
View File
@@ -53,7 +53,7 @@ export async function POST(request: NextRequest) {
[filename, data, category || 'other', room_id || null, location_target || 'gallery']
);
return NextResponse.json({ image: rows[0] });
return NextResponse.json({ data: rows[0] });
} catch (error) {
if ((error as Error).message === 'Unauthorized') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });