Refactor session ID extraction by exporting the extractSessionId function from broadcast.js. Update routes.js to utilize this function for consistent session ID handling during image uploads, improving code clarity and maintainability.
This commit is contained in:
@@ -66,7 +66,7 @@ export function getSessionIdForSocket(socketId) {
|
|||||||
return socketToSessionMap.get(socketId);
|
return socketToSessionMap.get(socketId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractSessionId(handshakeOrRequest) {
|
export function extractSessionId(handshakeOrRequest) {
|
||||||
// Unterstützt sowohl Socket.IO handshake als auch Express request
|
// Unterstützt sowohl Socket.IO handshake als auch Express request
|
||||||
const cookies = handshakeOrRequest.headers?.cookie || handshakeOrRequest.cookies || '';
|
const cookies = handshakeOrRequest.headers?.cookie || handshakeOrRequest.cookies || '';
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import multer from 'multer';
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { getSessionStatus, getClientsMap, getSessionIdForSocket } from './broadcast.js';
|
import { getSessionStatus, getClientsMap, getSessionIdForSocket, extractSessionId } from './broadcast.js';
|
||||||
|
|
||||||
// __dirname für ES-Module
|
// __dirname für ES-Module
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
@@ -63,16 +63,10 @@ export function setupRoutes(app, __dirname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prüfe, ob Benutzer eingeloggt ist
|
// Prüfe, ob Benutzer eingeloggt ist
|
||||||
// Extrahiere Session-ID wie in broadcast.js (entferne s: Präfix und Signatur)
|
// Verwende extractSessionId wie in broadcast.js, um die gleiche Session-ID zu erhalten
|
||||||
let sessionId = req.sessionID;
|
const sessionId = extractSessionId(req);
|
||||||
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()));
|
console.log(`[Bild-Upload] Session-ID (aus Cookie): ${sessionId}, req.sessionID: ${req.sessionID}, Alle Clients:`, Array.from(getClientsMap().keys()));
|
||||||
|
|
||||||
const clientsMap = getClientsMap();
|
const clientsMap = getClientsMap();
|
||||||
const client = clientsMap.get(sessionId);
|
const client = clientsMap.get(sessionId);
|
||||||
|
|||||||
Reference in New Issue
Block a user