Enhance session ID handling in image upload route by extracting and logging the session ID without the 's:' prefix. Improve client lookup error logging for better debugging during image uploads.
This commit is contained in:
@@ -63,11 +63,22 @@ export function setupRoutes(app, __dirname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prüfe, ob Benutzer eingeloggt ist
|
// Prüfe, ob Benutzer eingeloggt ist
|
||||||
const sessionId = req.sessionID;
|
// Extrahiere Session-ID wie in broadcast.js (entferne s: Präfix und Signatur)
|
||||||
|
let sessionId = req.sessionID;
|
||||||
|
if (sessionId && sessionId.startsWith('s:')) {
|
||||||
|
const parts = sessionId.split('.');
|
||||||
|
if (parts.length > 0) {
|
||||||
|
sessionId = parts[0].substring(2); // Entferne 's:' Präfix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[Bild-Upload] Session-ID: ${sessionId}, Alle Clients:`, Array.from(getClientsMap().keys()));
|
||||||
|
|
||||||
const clientsMap = getClientsMap();
|
const clientsMap = getClientsMap();
|
||||||
const client = clientsMap.get(sessionId);
|
const client = clientsMap.get(sessionId);
|
||||||
|
|
||||||
if (!client || !client.userName) {
|
if (!client || !client.userName) {
|
||||||
|
console.log(`[Bild-Upload] Client nicht gefunden für Session-ID: ${sessionId}`);
|
||||||
// Lösche hochgeladenes Bild, wenn nicht eingeloggt
|
// Lösche hochgeladenes Bild, wenn nicht eingeloggt
|
||||||
unlinkSync(req.file.path);
|
unlinkSync(req.file.path);
|
||||||
return res.status(401).json({ error: 'Nicht eingeloggt' });
|
return res.status(401).json({ error: 'Nicht eingeloggt' });
|
||||||
|
|||||||
Reference in New Issue
Block a user