fix: unique filenames for hero and moodboard uploads (prevent overwrite)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Etienne Delvarre
2026-05-29 14:38:42 +02:00
parent 4c31b3ad97
commit 0512a11d86
+2 -2
View File
@@ -252,7 +252,7 @@ app.post('/api/hero-upload', requireAuth, (req, res) => {
const buffer = Buffer.from(matches[2], 'base64'); const buffer = Buffer.from(matches[2], 'base64');
const uploadDir = path.join(__dirname, 'public', 'uploads'); const uploadDir = path.join(__dirname, 'public', 'uploads');
if (!fs.existsSync(uploadDir)) fs.mkdirSync(uploadDir, { recursive: true }); if (!fs.existsSync(uploadDir)) fs.mkdirSync(uploadDir, { recursive: true });
const filename = `hero.${ext}`; const filename = `hero-${Date.now()}.${ext}`;
fs.writeFileSync(path.join(uploadDir, filename), buffer); fs.writeFileSync(path.join(uploadDir, filename), buffer);
const publicPath = `/uploads/${filename}?t=${Date.now()}`; const publicPath = `/uploads/${filename}?t=${Date.now()}`;
res.json({ path: publicPath }); res.json({ path: publicPath });
@@ -272,7 +272,7 @@ app.post('/api/mood-upload', requireAuth, (req, res) => {
const buffer = Buffer.from(matches[2], 'base64'); const buffer = Buffer.from(matches[2], 'base64');
const uploadDir = path.join(__dirname, 'public', 'uploads'); const uploadDir = path.join(__dirname, 'public', 'uploads');
if (!fs.existsSync(uploadDir)) fs.mkdirSync(uploadDir, { recursive: true }); if (!fs.existsSync(uploadDir)) fs.mkdirSync(uploadDir, { recursive: true });
const filename = `mood-${index}.${ext}`; const filename = `mood-${index}-${Date.now()}.${ext}`;
fs.writeFileSync(path.join(uploadDir, filename), buffer); fs.writeFileSync(path.join(uploadDir, filename), buffer);
res.json({ path: `/uploads/${filename}?t=${Date.now()}` }); res.json({ path: `/uploads/${filename}?t=${Date.now()}` });
} catch (e) { } catch (e) {