Datei Upload und Download fix

Dieser Commit ist enthalten in:
hendrik_gebhardt@gmx.de
2026-01-10 20:54:24 +00:00
committet von Server Deploy
Ursprung 5b1f8b1cfe
Commit 671aaadc26
7 geänderte Dateien mit 186 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -12,6 +12,7 @@ const multer = require('multer');
const { getDb } = require('../database');
const logger = require('../utils/logger');
const { validators, stripHtml } = require('../middleware/validation');
const notificationService = require('../services/notificationService');
// Upload-Konfiguration für Knowledge-Anhänge
const UPLOAD_DIR = path.join(__dirname, '..', 'uploads', 'knowledge');
@ -498,6 +499,53 @@ router.post('/entries', (req, res) => {
logger.info(`Knowledge-Eintrag erstellt: ${title}`);
// Benachrichtigung an alle Nutzer senden
const io = req.app.get('io');
if (io) {
// Alle Nutzer abrufen (außer dem Ersteller)
const users = db.prepare(`
SELECT id FROM users
WHERE id != ?
`).all(req.user.id);
// Benachrichtigung für jeden Nutzer erstellen
users.forEach(user => {
notificationService.create(
user.id,
'knowledge:new_entry',
{
entryId: entry.id,
entryTitle: entry.title,
categoryName: category.name,
categoryId: category.id,
projectId: null,
actorId: req.user.id
},
io,
false // nicht persistent
);
});
// Socket.io Event für Echtzeit-Update senden
io.emit('knowledge:created', {
entry: {
id: entry.id,
categoryId: entry.category_id,
categoryName: category.name,
categoryColor: category.color,
title: entry.title,
url: entry.url,
notes: entry.notes,
position: entry.position,
attachmentCount: 0,
createdBy: entry.created_by,
creatorName: req.user.display_name,
createdAt: entry.created_at,
updatedAt: entry.updated_at
}
});
}
res.status(201).json({
id: entry.id,
categoryId: entry.category_id,

Datei anzeigen

@ -58,6 +58,10 @@ const NOTIFICATION_TYPES = {
'approval:rejected': {
title: (data) => 'Genehmigung abgelehnt',
message: (data) => `"${data.proposalTitle}" wurde abgelehnt`
},
'knowledge:new_entry': {
title: (data) => 'Neuer Wissenseintrag',
message: (data) => `Neuer Eintrag: "${data.entryTitle}" in ${data.categoryName}`
}
};
@ -84,8 +88,8 @@ const notificationService = {
const message = typeConfig.message(data);
const result = db.prepare(`
INSERT INTO notifications (user_id, type, title, message, task_id, project_id, proposal_id, actor_id, is_persistent)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO notifications (user_id, type, title, message, task_id, project_id, proposal_id, actor_id, is_persistent, data)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
userId,
type,
@ -95,7 +99,8 @@ const notificationService = {
data.projectId || null,
data.proposalId || null,
data.actorId || null,
persistent ? 1 : 0
persistent ? 1 : 0,
JSON.stringify(data) // Zusätzliche Daten als JSON speichern
);
const notification = db.prepare(`
@ -260,6 +265,16 @@ const notificationService = {
* Benachrichtigung formatieren für Frontend
*/
formatNotification(notification) {
// Parse zusätzliche Daten wenn vorhanden
let additionalData = {};
if (notification.data) {
try {
additionalData = JSON.parse(notification.data);
} catch (e) {
// Ignore parse errors
}
}
return {
id: notification.id,
userId: notification.user_id,
@ -274,7 +289,10 @@ const notificationService = {
actorColor: notification.actor_color,
isRead: notification.is_read === 1,
isPersistent: notification.is_persistent === 1,
createdAt: notification.created_at
createdAt: notification.created_at,
// Zusätzliche Daten für Knowledge-Einträge
entryId: additionalData.entryId || null,
categoryId: additionalData.categoryId || null
};
},