166 build - интерфейс

This commit is contained in:
2026-09-29 11:35:20 +03:00
parent 615cf5d109
commit 0df2836b07
8 changed files with 224 additions and 89 deletions

View File

@@ -117,11 +117,14 @@ class MatchAccess:
return {
"game_id": game_id, "participant_id": pid,
"role": "controller" if own else "viewer", "can_control": own,
"control_device_id": lease.owner_device_id if own else "",
"can_claim": self._eligible(user) and not active,
"can_resume": bool(active and lease.owner_user_id == user.id and self._eligible(user) and not own),
"can_force_claim": bool(user.is_admin and not own),
"generation": lease.generation if lease else 0,
"revision": lease.revision if lease else 0,
"owner": {"name": lease.owner_name, "participant_id": lease.owner_participant_id} if active else None,
"owner": {"name": lease.owner_name, "participant_id": lease.owner_participant_id,
"is_self": lease.owner_user_id == user.id} if active else None,
"expires_at": _iso(lease.expires_at) if active else "",
"lease_remaining_ms": max(0, int((lease.expires_at - now).total_seconds() * 1000)) if active else 0,
"server_time": _iso(now),
@@ -178,6 +181,19 @@ class MatchAccess:
if self._active(lease, now) and not (force and user.is_admin):
fail(409, "control_busy", "Матч уже находится под управлением оператора")
target = member
elif action == "resume":
# An explicit move between this account's browsers. Matching
# display names never grant authority; the authenticated ID does.
if not self._eligible(user) or not self._active(lease, now) or lease.owner_user_id != user.id:
fail(403, "view_only", "Продолжить здесь можно только управление своего аккаунта")
target = member
if not target.device_id and lease.owner_device_id:
device = session.scalar(select(VmixDevice).where(
VmixDevice.device_uuid == lease.owner_device_id,
VmixDevice.wfl_user_id == user.id,
))
if device is not None:
target.device_id = device.device_uuid
else:
self._owned(lease, user, pid, generation)
target = member
@@ -186,7 +202,7 @@ class MatchAccess:
if not target or not target.can_claim or target.last_seen_at < now - timedelta(seconds=PARTICIPANT_SECONDS):
fail(409, "target_unavailable", "Выбранный участник отключён или не может управлять")
values: dict[str, Any] = {"updated_at": now}
if action in {"claim", "transfer"} and target.device_id:
if action in {"claim", "transfer", "resume"} and target.device_id:
# Serialize claims that target the same physical Agent, even
# across different matches of one account.
session.scalar(select(VmixDevice).where(VmixDevice.device_uuid == target.device_id).with_for_update())
@@ -450,6 +466,11 @@ def create_match_access_router(access: MatchAccess, auth_dependency: Callable[..
def claim(external_id: str, request: Request, payload: ClaimPayload, user: HockeyUser = Depends(auth_dependency)):
return access.change(external_id, user, request, "claim", force=payload.force)
@router.post("/games/{external_id}/access/resume")
@db_endpoint
def resume(external_id: str, request: Request, user: HockeyUser = Depends(auth_dependency)):
return access.change(external_id, user, request, "resume")
@router.post("/games/{external_id}/access/leave")
@db_endpoint
def leave(external_id: str, request: Request, user: HockeyUser = Depends(auth_dependency)):