Files
live/backend/models/audit.py
T

51 lines
2.6 KiB
Python

import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from database import Base
class ViewerSession(Base):
__tablename__ = "viewer_sessions"
session_id: Mapped[str] = mapped_column(String(64), primary_key=True)
stream_id: Mapped[int] = mapped_column(ForeignKey("streams.id"), index=True)
node_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
node_name: Mapped[str | None] = mapped_column(String(200), nullable=True)
quality: Mapped[str | None] = mapped_column(String(64), nullable=True)
playback_state: Mapped[str] = mapped_column(String(32), default="idle")
buffered_seconds: Mapped[float | None] = mapped_column(Float, nullable=True)
error: Mapped[str | None] = mapped_column(Text, nullable=True)
remote_adjusted: Mapped[bool] = mapped_column(Boolean, default=False)
last_heartbeat: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class ControlSession(Base):
__tablename__ = "control_sessions"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
token: Mapped[str] = mapped_column(String(128), unique=True, default=lambda: uuid.uuid4().hex)
stream_id: Mapped[int] = mapped_column(ForeignKey("streams.id"), index=True)
operator: Mapped[str] = mapped_column(String(128), default="administrator")
expires_at: Mapped[datetime] = mapped_column(DateTime, index=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class ControlCommand(Base):
__tablename__ = "control_commands"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
control_session_id: Mapped[int] = mapped_column(ForeignKey("control_sessions.id"), index=True)
stream_id: Mapped[int] = mapped_column(ForeignKey("streams.id"), index=True)
target_session_id: Mapped[str] = mapped_column(ForeignKey("viewer_sessions.session_id"), index=True)
operator: Mapped[str] = mapped_column(String(128), default="administrator")
action: Mapped[str] = mapped_column(String(32))
value: Mapped[str | None] = mapped_column(String(256), nullable=True)
status: Mapped[str] = mapped_column(String(32), default="pending")
result: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
claimed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)