chore: brand icon and title by default

This commit is contained in:
admin committed 2026-10-22 20:23:33 +08:00
1 parent 8e61dc111c
commit b4fcbd38ba
17 files changed
+1254 -213

No files matched your search

+50
View File
@@ -124,6 +124,28 @@ def _valid_replay_url(url: str | None) -> str | None:
return url
def _parse_scheduled_at(value: str | None) -> datetime | None:
"""Turn the ISO string a client sends into the value the column stores.
`scheduled_at` is a DateTime column and SQLite's binder rejects a str outright
("SQLite DateTime type only accepts Python datetime and date objects"), so an
update that carried a schedule failed with a 500 — a large part of why the
schedule looked like a property that could only be set at creation.
Creation stores UTC wall-clock with tzinfo dropped; do the same here.
"""
if value is None:
return None
text = str(value).strip()
if not text:
return None
try:
parsed = datetime.fromisoformat(text.replace("Z", "+00:00"))
except ValueError as exc:
raise HTTPException(status_code=422, detail="预定开播时间格式无效") from exc
return parsed.replace(tzinfo=None) if parsed.tzinfo else parsed
def _utc_iso(moment: datetime) -> str:
"""Render a stored timestamp as an explicit UTC instant for JSON.
@@ -263,6 +285,14 @@ async def viewer_heartbeat(stream_id: int, body: ViewerHeartbeat,
stream = await StreamService(db).get_stream(stream_id)
if not stream:
raise HTTPException(status_code=404, detail="节目不存在")
if stream.status.value != "live":
# Audit sessions describe live playback: node, rendition, buffer and remote
# adjustment only mean something while the programme is on air. A replay is
# a plain file served straight to the browser, so recording a session for it
# only filled the audit board with rows nobody could act on. This answers a
# no-op instead of an error so a tab left open across the end of a broadcast
# does not start failing its heartbeats.
return {"ok": True, "remote_adjusted": False, "audit_active": False}
session_id = body.session_id.strip()
if not session_id or len(session_id) > 64:
raise HTTPException(status_code=422, detail="观众会话 ID 无效")
@@ -428,6 +458,14 @@ async def update_stream(stream_id: int, body: StreamUpdate, db: AsyncSession = D
if replay_fields.intersection(updates) and existing.status.value != "ended":
raise HTTPException(status_code=409, detail="仅已结束的节目可以配置回放和章节")
if "title" in updates:
title = (updates["title"] or "").strip()
if not title:
raise HTTPException(status_code=422, detail="节目标题不能为空")
updates["title"] = title
if "scheduled_at" in updates:
updates["scheduled_at"] = _parse_scheduled_at(updates["scheduled_at"])
if updates.get("replay_file"):
_media_path(updates["replay_file"])
if "replay_url" in updates and updates["replay_url"] is not None:
@@ -561,6 +599,8 @@ async def create_remote_session(stream_id: int, body: RemoteSessionCreate,
stream = await StreamService(db).get_stream(stream_id)
if not stream or not stream.remote_control_enabled:
raise HTTPException(status_code=409, detail="节目未启用远程控制")
if stream.status.value != "live":
raise HTTPException(status_code=409, detail="节目未在直播,无需控制回放观众")
expires_in = min(max(body.expires_in, 30), 3600)
session = ControlSession(
token=secrets.token_urlsafe(24),
@@ -586,6 +626,8 @@ async def send_remote_command(stream_id: int, body: RemoteCommand,
stream = await StreamService(db).get_stream(stream_id)
if not stream or not stream.remote_control_enabled:
raise HTTPException(status_code=409, detail="节目未启用远程控制")
if stream.status.value != "live":
raise HTTPException(status_code=409, detail="节目未在直播,无需控制回放观众")
if body.action not in {"switch_node", "switch_quality", "restore_auto"}:
raise HTTPException(status_code=422, detail="不支持的远程命令")
if not body.targets:
@@ -616,6 +658,14 @@ async def send_remote_command(stream_id: int, body: RemoteCommand,
@router.get("/{stream_id}/remote-command")
async def poll_remote_command(stream_id: int, session_id: str,
db: AsyncSession = Depends(get_db)):
stream = await StreamService(db).get_stream(stream_id)
if not stream:
raise HTTPException(status_code=404, detail="节目不存在")
if stream.status.value != "live" or not stream.remote_control_enabled:
# Same rule as heartbeats: nobody is audited during a replay, and a
# programme that never opted into control must not have viewers polling for
# commands either. Answer "nothing to do" instead of registering a session.
return None
viewer = await db.get(ViewerSession, session_id)
if not viewer:
raise HTTPException(status_code=404, detail="观众会话不存在")