diff --git a/backend/src/tools/dateien/routes.js b/backend/src/tools/dateien/routes.js index c1b6205..e965d06 100644 --- a/backend/src/tools/dateien/routes.js +++ b/backend/src/tools/dateien/routes.js @@ -183,9 +183,11 @@ router.get('/', authenticate, (req, res) => { router.post('/', authenticate, (req, res) => { const uid = req.user.id; - const maxCount = parseInt(getSetting('file_max_count') || '20'); - const count = db.prepare('SELECT COUNT(*) c FROM files WHERE user_id=?').get(uid).c; - if (count >= maxCount) return res.status(400).json({ error: `Maximum ${maxCount} Dateien erlaubt` }); + const maxSizeMb = parseInt(getSetting('file_max_size_mb') || '50'); + const totalLimitMb= parseInt(getSetting('file_total_size_mb') || '500'); + const usedBytes = db.prepare('SELECT COALESCE(SUM(size),0) AS s FROM files WHERE user_id=?').get(uid).s; + if (usedBytes >= totalLimitMb * 1024 * 1024) + return res.status(400).json({ error: `Gesamtlimit von ${totalLimitMb} MB erreicht` }); getUpload().single('file')(req, res, err => { if (err) return res.status(400).json({ error: err.message }); if (!req.file) return res.status(400).json({ error: 'Keine Datei' }); @@ -200,9 +202,9 @@ router.get('/storage', authenticate, (req, res) => { const uid = req.user.id; const used = db.prepare('SELECT COALESCE(SUM(size),0) AS s FROM files WHERE user_id=?').get(uid).s; const count = db.prepare('SELECT COUNT(*) AS c FROM files WHERE user_id=?').get(uid).c; - const maxSizeMb = parseInt(getSetting('file_max_size_mb') || '50'); - const maxCount = parseInt(getSetting('file_max_count') || '20'); - res.json({ used, count, maxSizeMb, maxCount }); + const maxSizeMb = parseInt(getSetting('file_max_size_mb') || '50'); + const totalLimitMb = parseInt(getSetting('file_total_size_mb') || '500'); + res.json({ used, count, maxSizeMb, totalLimitMb }); }); router.get('/:id/download', authenticate, async (req, res) => { @@ -295,7 +297,7 @@ router.get('/settings', authenticate, requireAdmin, (req, res) => { res.json(obj); }); router.put('/settings', authenticate, requireAdmin, (req, res) => { - for (const key of ['file_max_size_mb','file_max_count','file_allowed_ext']) { + for (const key of ['file_max_size_mb','file_total_size_mb','file_allowed_ext']) { if (req.body[key] !== undefined) db.prepare('INSERT OR REPLACE INTO admin_settings (key,value) VALUES (?,?)').run(key, String(req.body[key])); } diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c7f66f9..1b947a4 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -686,7 +686,7 @@ function BestellStats() {