b969b7e5af
- restream.py: eliminar -reconnect_streamed de ffmpeg para evitar rebobinados al reconectar (el proveedor re-enviaba desde keyframe anterior causando PTS backward). El loop de Python gestiona las reconexiones con conexión fresca. - restream.py: eliminar _drain_queue del loop de reconexión para que el buffer de la cola cubra el tiempo de reconexión sin pantalla negra en el player. - restream.py: añadir buffer_server_bytes/secs/capacity a stats() y método _log_stream_event() para persistir eventos de caída y recuperación en BD. - models/stream_event.py: nuevo modelo StreamEvent para registro de fallos. - database.py: registrar StreamEvent en init_db. - api/admin/logs.py: nuevos endpoints GET/DELETE /logs/events. - Dashboard.tsx: mostrar reserva de buffer del servidor (capacidad + estado). - Logs.tsx: añadir pestaña "Fallos de stream" con tabla de eventos persistidos. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, UniqueConstraint, func
|
|
from sqlalchemy.orm import relationship
|
|
import bcrypt as _bcrypt
|
|
from ..database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String(100), unique=True, nullable=False, index=True)
|
|
password_hash = Column(String(200), nullable=False)
|
|
max_connections = Column(Integer, default=1, nullable=False)
|
|
expiry_date = Column(DateTime(timezone=True), nullable=True)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
is_priority = Column(Boolean, default=False, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
catalog_entries = relationship("UserCatalogEntry", back_populates="user", cascade="all, delete-orphan")
|
|
provider_preferences = relationship("UserProviderPreference", back_populates="user", cascade="all, delete-orphan", order_by="UserProviderPreference.priority")
|
|
|
|
def set_password(self, password: str) -> None:
|
|
hashed = _bcrypt.hashpw(password.encode(), _bcrypt.gensalt())
|
|
self.password_hash = hashed.decode()
|
|
|
|
def verify_password(self, password: str) -> bool:
|
|
return _bcrypt.checkpw(password.encode(), self.password_hash.encode())
|
|
|
|
|
|
class UserCatalogEntry(Base):
|
|
__tablename__ = "user_catalog_entries"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
category_id = Column(Integer, ForeignKey("categories.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
user = relationship("User", back_populates="catalog_entries")
|
|
category = relationship("Category", back_populates="catalog_entries")
|
|
|
|
|
|
class UserCustomCatalogEntry(Base):
|
|
__tablename__ = "user_custom_catalog_entries"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
custom_category_id = Column(Integer, ForeignKey("custom_categories.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "custom_category_id", name="uq_user_custom_cat"),
|
|
)
|
|
|
|
|
|
class UserProviderPreference(Base):
|
|
__tablename__ = "user_provider_preferences"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
provider_account_id = Column(Integer, ForeignKey("provider_accounts.id", ondelete="CASCADE"), nullable=False)
|
|
priority = Column(Integer, default=0, nullable=False)
|
|
|
|
user = relationship("User", back_populates="provider_preferences")
|
|
provider_account = relationship("ProviderAccount")
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "provider_account_id", name="uq_user_provider_pref"),
|
|
)
|