From cc2dc834012c0b708db8f0fd02b4c86318e7665d Mon Sep 17 00:00:00 2001 From: juancarmore Date: Sat, 12 Apr 2025 13:45:34 +0200 Subject: [PATCH] backend: Rename getRoomSecretRole to getRoomRoleBySecret and update related calls --- backend/src/helpers/room.helper.ts | 1 - .../src/middlewares/participant.middleware.ts | 2 +- backend/src/services/participant.service.ts | 2 +- backend/src/services/room.service.ts | 16 ++-------------- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/backend/src/helpers/room.helper.ts b/backend/src/helpers/room.helper.ts index 088b5bc..4e87390 100644 --- a/backend/src/helpers/room.helper.ts +++ b/backend/src/helpers/room.helper.ts @@ -34,7 +34,6 @@ export class MeetRoomHelper { static extractSecretsFromRoom(room: MeetRoom): { publisherSecret: string; moderatorSecret: string } { const { publisherRoomUrl, moderatorRoomUrl } = room; - const publisherUrl = new URL(publisherRoomUrl); const publisherSecret = publisherUrl.searchParams.get('secret') || ''; const moderatorUrl = new URL(moderatorRoomUrl); diff --git a/backend/src/middlewares/participant.middleware.ts b/backend/src/middlewares/participant.middleware.ts index 4fc0be9..b265c8b 100644 --- a/backend/src/middlewares/participant.middleware.ts +++ b/backend/src/middlewares/participant.middleware.ts @@ -20,7 +20,7 @@ export const configureTokenAuth = async (req: Request, res: Response, next: Next try { const { roomId, secret } = req.body as TokenOptions; - role = await roomService.getRoomSecretRole(roomId, secret); + role = await roomService.getRoomRoleBySecret(roomId, secret); } catch (error) { logger.error('Error getting room secret role', error); return res.status(500).json({ message: 'Internal server error' }); diff --git a/backend/src/services/participant.service.ts b/backend/src/services/participant.service.ts index 53f4b77..5c552f6 100644 --- a/backend/src/services/participant.service.ts +++ b/backend/src/services/participant.service.ts @@ -30,7 +30,7 @@ export class ParticipantService { throw errorParticipantNotFound(participantName, roomId); } - const role = await this.roomService.getRoomSecretRole(roomId, secret); + const role = await this.roomService.getRoomRoleBySecret(roomId, secret); const token = await this.generateParticipantToken(role, options); this.logger.verbose(`Participant token generated for room ${roomId}`); return token; diff --git a/backend/src/services/room.service.ts b/backend/src/services/room.service.ts index b30ceef..d201fa4 100644 --- a/backend/src/services/room.service.ts +++ b/backend/src/services/room.service.ts @@ -232,21 +232,9 @@ export class RoomService { * @throws Error if the moderator or publisher secrets cannot be extracted from their URLs * @throws Error if the provided secret doesn't match any of the room's secrets (unauthorized) */ - async getRoomSecretRole(roomId: string, secret: string): Promise { + async getRoomRoleBySecret(roomId: string, secret: string): Promise { const room = await this.getMeetRoom(roomId); - const { moderatorRoomUrl, publisherRoomUrl } = room; - - const extractSecret = (urlString: string, type: string): string => { - const url = new URL(urlString); - const secret = url.searchParams.get('secret'); - - if (!secret) throw new Error(`${type} secret not found`); - - return secret; - }; - - const publisherSecret = extractSecret(publisherRoomUrl, 'Publisher'); - const moderatorSecret = extractSecret(moderatorRoomUrl, 'Moderator'); + const { moderatorSecret, publisherSecret } = MeetRoomHelper.extractSecretsFromRoom(room); switch (secret) { case moderatorSecret: