Fix wallpaper path handling in event endpoints

This commit is contained in:
2025-05-01 09:20:22 -04:00
parent d2e27c4390
commit efa37db52c

View File

@@ -83,7 +83,15 @@ const upload = multer({
app.get('/api/events', async (req: Request, res: Response) => {
try {
const rows = await db.all('SELECT * FROM events');
res.json(rows);
// Add the full path to wallpapers
const events = rows.map(event => ({
...event,
wallpaper: event.wallpaper ? `/uploads/wallpapers/${event.wallpaper}` : null,
needed_items: event.needed_items ? JSON.parse(event.needed_items) : []
}));
res.json(events);
} catch (error) {
console.error('Error fetching events:', error);
res.status(500).json({ error: 'Internal server error' });
@@ -107,6 +115,11 @@ app.get('/api/events/:slug', async (req: Request, res: Response) => {
event.needed_items = [];
}
// Add the full path to the wallpaper
if (event.wallpaper) {
event.wallpaper = `/uploads/wallpapers/${event.wallpaper}`;
}
res.json(event);
} catch (error) {
console.error('Error fetching event:', error);