165 build - ChatGPT-6 поправка интерфейса

This commit is contained in:
2026-09-29 11:11:17 +03:00
parent 5d416b729b
commit 615cf5d109
7 changed files with 825 additions and 35 deletions

106
app.py
View File

@@ -1,6 +1,8 @@
from __future__ import annotations
import json
import os
import tempfile
from pathlib import Path
from datetime import date
from typing import Any
@@ -33,7 +35,7 @@ from khl_site.khl_data_center import APP as khl_site_app, configure_storage, syn
from hockey_data.khl_career import KhlCareerService
BASE_DIR = Path(__file__).resolve().parent
BUILD_VERSION = "2026.09.27.3"
BUILD_VERSION = "2026.09.29.2"
# compatibility: BUILD_VERSION = "2026.09.24.2"
# compatibility: BUILD_VERSION = "2026.09.23.8"
# compatibility: BUILD_VERSION = "2026.09.23.7"
@@ -90,6 +92,89 @@ hockey_agent_hub = VmixAgentHub(hockey_database, settings=hockey_settings)
hockey_idle_matches = IdleMatchReaper(hockey_database, hockey_agent_hub)
PLAYER_PANEL_BUTTONS_PATH = BASE_DIR / "settings" / "hockey_player_panel_buttons.json"
def _normalise_player_panel_title_buttons(payload: Any) -> dict[str, Any]:
"""Normalise operator-configured Preview buttons for player-selection panels.
This deliberately lives in a standalone JSON file rather than app.js / the
main UI Builder document. A studio can therefore change title assignments
without editing application code or rebuilding the whole layout.
"""
source = payload if isinstance(payload, dict) else {}
rows = source.get("buttons") if isinstance(source.get("buttons"), list) else []
result: list[dict[str, Any]] = []
used_ids: set[str] = set()
for index, raw in enumerate(rows[:128]):
if not isinstance(raw, dict):
continue
panel_id = str(raw.get("panel_id") or "").strip()[:64]
label = str(raw.get("label") or "").strip()[:80]
input_ref = str(raw.get("input") or raw.get("input_ref") or "").strip()[:300]
if not panel_id or not label:
continue
button_id = str(raw.get("id") or f"panel_title_{index + 1}").strip()
button_id = "".join(ch if ch.isascii() and (ch.isalnum() or ch in "_-") else "_" for ch in button_id)[:64].strip("_")
if not button_id:
button_id = f"panel_title_{index + 1}"
base_id = button_id
suffix = 2
while button_id in used_ids:
ending = f"_{suffix}"
button_id = f"{base_id[:64 - len(ending)]}{ending}"
suffix += 1
used_ids.add(button_id)
try:
sort_order = int(raw.get("sort_order", index * 10))
except (TypeError, ValueError):
sort_order = index * 10
result.append({
"id": button_id,
"panel_id": panel_id,
"label": label,
"description": str(raw.get("description") or "").strip()[:300],
"icon": str(raw.get("icon") or "▶").strip()[:32] or "▶",
"icon_only": raw.get("icon_only") is True,
"input": input_ref,
"enabled": raw.get("enabled") is not False,
"sort_order": max(0, min(100000, sort_order)),
})
result.sort(key=lambda item: (str(item["panel_id"]), int(item["sort_order"]), str(item["label"]).casefold()))
return {"version": 1, "buttons": result}
def _load_player_panel_title_buttons() -> dict[str, Any]:
PLAYER_PANEL_BUTTONS_PATH.parent.mkdir(parents=True, exist_ok=True)
if not PLAYER_PANEL_BUTTONS_PATH.exists():
payload = {"version": 1, "buttons": []}
try:
with PLAYER_PANEL_BUTTONS_PATH.open("x", encoding="utf-8") as target:
target.write(json.dumps(payload, ensure_ascii=False, indent=2) + "\n")
except FileExistsError:
return _load_player_panel_title_buttons()
return payload
try:
raw = json.loads(PLAYER_PANEL_BUTTONS_PATH.read_text(encoding="utf-8"))
except (OSError, ValueError, TypeError) as error:
raise HTTPException(status_code=500, detail="Не удалось прочитать настройки кнопок титров. Проверьте settings/hockey_player_panel_buttons.json.") from error
return _normalise_player_panel_title_buttons(raw)
def _save_player_panel_title_buttons(payload: Any) -> dict[str, Any]:
normalised = _normalise_player_panel_title_buttons(payload)
PLAYER_PANEL_BUTTONS_PATH.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=PLAYER_PANEL_BUTTONS_PATH.parent,
prefix=".panel-buttons-", suffix=".tmp", delete=False) as target:
tmp_path = Path(target.name)
target.write(json.dumps(normalised, ensure_ascii=False, indent=2) + "\n")
try:
tmp_path.replace(PLAYER_PANEL_BUTTONS_PATH)
finally:
tmp_path.unlink(missing_ok=True)
return normalised
@app.on_event("startup")
async def hockey_mapping_auto_refresh_startup() -> None:
await run_db(sync_storage)
@@ -315,6 +400,25 @@ async def save_hockey_prematch_buttons(payload: dict[str, Any]) -> dict[str, Any
}
@app.get(
"/api/hockey/ui/player-panel-buttons",
dependencies=[Depends(hockey_auth.require_user)],
tags=["Hockey UI"],
)
async def get_hockey_player_panel_buttons() -> dict[str, Any]:
return _load_player_panel_title_buttons()
@app.post(
"/api/hockey/ui/player-panel-buttons",
dependencies=[Depends(hockey_auth.require_admin)],
tags=["Hockey UI"],
)
async def save_hockey_player_panel_buttons(payload: dict[str, Any]) -> dict[str, Any]:
saved = _save_player_panel_title_buttons(payload)
return {"ok": True, **saved}
@app.post(
"/api/hockey/ui/triggers",
dependencies=[Depends(hockey_auth.require_admin)],