fix: image upload returns correct data structure for all editors
This commit is contained in:
@@ -744,7 +744,7 @@ function SocialEditor({ event, setEvent, images, onSave, onCancel }: any) {
|
|||||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ filename: f.name, data: b64, category: 'social', room_id: null, location_target: 'social' }),
|
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); }
|
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
|
||||||
}
|
}
|
||||||
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
||||||
@@ -856,7 +856,7 @@ function RoomEditor({ room, setRoom, images, onSave, onCancel }: any) {
|
|||||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
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'}` }),
|
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); }
|
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
|
||||||
}
|
}
|
||||||
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
||||||
@@ -1192,7 +1192,7 @@ function PlaceEditor({ place, setPlace, images, onSave, onCancel }: any) {
|
|||||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
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'}` }),
|
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); }
|
} catch { const b = await readFileBase64(f); newPhotos.push(b); }
|
||||||
}
|
}
|
||||||
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
setLocalPhotos(prev => [...prev, ...newPhotos]);
|
||||||
@@ -1310,7 +1310,7 @@ function BrandSection({ images, onToast }: { images: Image[]; onToast: (m: strin
|
|||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const d = await res.json();
|
const d = await res.json();
|
||||||
setConfig(prev => ({ ...prev, [key]: d.data }));
|
setConfig(prev => ({ ...prev, [key]: d.data.data }));
|
||||||
onToast('Image uploaded!', 'success');
|
onToast('Image uploaded!', 'success');
|
||||||
}
|
}
|
||||||
} catch { onToast('Upload failed', 'error'); }
|
} catch { onToast('Upload failed', 'error'); }
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export async function POST(request: NextRequest) {
|
|||||||
[filename, data, category || 'other', room_id || null, location_target || 'gallery']
|
[filename, data, category || 'other', room_id || null, location_target || 'gallery']
|
||||||
);
|
);
|
||||||
|
|
||||||
return NextResponse.json({ image: rows[0] });
|
return NextResponse.json({ data: rows[0] });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if ((error as Error).message === 'Unauthorized') {
|
if ((error as Error).message === 'Unauthorized') {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
|
|||||||
Reference in New Issue
Block a user