keep original presentation name
All checks were successful
Build & Push Docker Image / build (push) Successful in 6m0s

This commit is contained in:
2026-02-27 16:51:17 +01:00
parent ab52ca4529
commit 4d0756d864
3 changed files with 16 additions and 4 deletions

View File

@@ -354,6 +354,9 @@ export async function initDatabase() {
if (!(await db.columnExists('rooms', 'presentation_file'))) { if (!(await db.columnExists('rooms', 'presentation_file'))) {
await db.exec('ALTER TABLE rooms ADD COLUMN presentation_file TEXT DEFAULT NULL'); await db.exec('ALTER TABLE rooms ADD COLUMN presentation_file TEXT DEFAULT NULL');
} }
if (!(await db.columnExists('rooms', 'presentation_name'))) {
await db.exec('ALTER TABLE rooms ADD COLUMN presentation_name TEXT DEFAULT NULL');
}
// ── Default admin ─────────────────────────────────────────────────────── // ── Default admin ───────────────────────────────────────────────────────
const adminEmail = process.env.ADMIN_EMAIL || 'admin@example.com'; const adminEmail = process.env.ADMIN_EMAIL || 'admin@example.com';

View File

@@ -564,6 +564,12 @@ router.post('/:uid/presentation', authenticateToken, async (req, res) => {
// Max 50MB // Max 50MB
if (buffer.length > 50 * 1024 * 1024) return res.status(400).json({ error: 'File must not exceed 50MB' }); if (buffer.length > 50 * 1024 * 1024) return res.status(400).json({ error: 'File must not exceed 50MB' });
// Preserve original filename (sent as X-Filename header)
const rawName = req.headers['x-filename'];
const originalName = rawName
? decodeURIComponent(rawName).replace(/[^a-zA-Z0-9._\- ]/g, '_').slice(0, 200)
: `presentation.${ext}`;
const filename = `${room.uid}_${Date.now()}.${ext}`; const filename = `${room.uid}_${Date.now()}.${ext}`;
const filepath = path.join(presentationsDir, filename); const filepath = path.join(presentationsDir, filename);
@@ -574,7 +580,7 @@ router.post('/:uid/presentation', authenticateToken, async (req, res) => {
} }
fs.writeFileSync(filepath, buffer); fs.writeFileSync(filepath, buffer);
await db.run('UPDATE rooms SET presentation_file = ?, updated_at = CURRENT_TIMESTAMP WHERE uid = ?', [filename, req.params.uid]); await db.run('UPDATE rooms SET presentation_file = ?, presentation_name = ?, updated_at = CURRENT_TIMESTAMP WHERE uid = ?', [filename, originalName, req.params.uid]);
const updated = await db.get('SELECT * FROM rooms WHERE uid = ?', [req.params.uid]); const updated = await db.get('SELECT * FROM rooms WHERE uid = ?', [req.params.uid]);
res.json({ room: updated }); res.json({ room: updated });
} catch (err) { } catch (err) {
@@ -595,7 +601,7 @@ router.delete('/:uid/presentation', authenticateToken, async (req, res) => {
if (fs.existsSync(filepath)) fs.unlinkSync(filepath); if (fs.existsSync(filepath)) fs.unlinkSync(filepath);
} }
await db.run('UPDATE rooms SET presentation_file = NULL, updated_at = CURRENT_TIMESTAMP WHERE uid = ?', [req.params.uid]); await db.run('UPDATE rooms SET presentation_file = NULL, presentation_name = NULL, updated_at = CURRENT_TIMESTAMP WHERE uid = ?', [req.params.uid]);
const updated = await db.get('SELECT * FROM rooms WHERE uid = ?', [req.params.uid]); const updated = await db.get('SELECT * FROM rooms WHERE uid = ?', [req.params.uid]);
res.json({ room: updated }); res.json({ room: updated });
} catch (err) { } catch (err) {

View File

@@ -184,7 +184,10 @@ export default function RoomDetail() {
try { try {
const arrayBuffer = await file.arrayBuffer(); const arrayBuffer = await file.arrayBuffer();
const res = await api.post(`/rooms/${uid}/presentation`, arrayBuffer, { const res = await api.post(`/rooms/${uid}/presentation`, arrayBuffer, {
headers: { 'Content-Type': file.type }, headers: {
'Content-Type': file.type,
'X-Filename': encodeURIComponent(file.name),
},
}); });
setRoom(res.data.room); setRoom(res.data.room);
setEditRoom(res.data.room); setEditRoom(res.data.room);
@@ -607,7 +610,7 @@ export default function RoomDetail() {
<div className="min-w-0"> <div className="min-w-0">
<p className="text-xs text-th-text-s">{t('room.presentationCurrent')}</p> <p className="text-xs text-th-text-s">{t('room.presentationCurrent')}</p>
<p className="text-sm text-th-text font-medium truncate"> <p className="text-sm text-th-text font-medium truncate">
presentation.{room.presentation_file.split('.').pop()} {room.presentation_name || `presentation.${room.presentation_file?.split('.').pop()}`}
</p> </p>
</div> </div>
</div> </div>