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);
|
||||
}
|
||||
|
||||
function extractSessionId(handshakeOrRequest) {
|
||||
export function extractSessionId(handshakeOrRequest) {
|
||||
// Unterstützt sowohl Socket.IO handshake als auch Express request
|
||||
const cookies = handshakeOrRequest.headers?.cookie || handshakeOrRequest.cookies || '';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import multer from 'multer';
|
||||
import crypto from 'crypto';
|
||||
|
||||
import axios from 'axios';
|
||||
import { getSessionStatus, getClientsMap, getSessionIdForSocket } from './broadcast.js';
|
||||
import { getSessionStatus, getClientsMap, getSessionIdForSocket, extractSessionId } from './broadcast.js';
|
||||
|
||||
// __dirname für ES-Module
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -63,16 +63,10 @@ export function setupRoutes(app, __dirname) {
|
||||
}
|
||||
|
||||
// Prüfe, ob Benutzer eingeloggt ist
|
||||
// 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
|
||||
}
|
||||
}
|
||||
// Verwende extractSessionId wie in broadcast.js, um die gleiche Session-ID zu erhalten
|
||||
const sessionId = extractSessionId(req);
|
||||
|
||||
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 client = clientsMap.get(sessionId);
|
||||
|
||||
Reference in New Issue
Block a user