add endpoint get room/{room_id}
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Body
|
||||
from fastapi import APIRouter, Body, HTTPException
|
||||
from app.models.voice_rooms import JoinRoomRequest
|
||||
from app.services.voice_rooms import VoiceRoomService
|
||||
from app.realtime.voice_hub import voice_hub
|
||||
@ -43,6 +43,35 @@ async def list_rooms():
|
||||
|
||||
return result
|
||||
|
||||
@router.get("/rooms/{room_id}")
|
||||
async def get_room(room_id: str):
|
||||
room = await service.get_room(room_id)
|
||||
|
||||
users_map = voice_hub.rooms.get(room_id, {})
|
||||
usernames = list(users_map.keys())
|
||||
users_count = len(usernames)
|
||||
|
||||
if room["public"]:
|
||||
# 🟢 публичная — полная информация
|
||||
return {
|
||||
"id": room["id"],
|
||||
"name": room["name"],
|
||||
"public": True,
|
||||
"owner": room.get("owner"),
|
||||
"max_users": room.get("max_users"),
|
||||
"users": users_count,
|
||||
"usernames": usernames,
|
||||
"created_at": room["created_at"].isoformat()
|
||||
if room.get("created_at") else None,
|
||||
}
|
||||
|
||||
# 🔒 приватная — НЕЛЬЗЯ получать по room_id напрямую
|
||||
# иначе это обход invite-кода
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Access to private room is forbidden",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/rooms")
|
||||
async def create_room(
|
||||
|
||||
Reference in New Issue
Block a user