feat: track download logs (ip, browser, device, time)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""SQLAlchemy models."""
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, DateTime, BigInteger, Text, Index
|
||||
from sqlalchemy import Column, Integer, String, DateTime, BigInteger, Text, Index, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
|
||||
|
||||
@@ -28,3 +29,19 @@ class Video(Base):
|
||||
__table_args__ = (
|
||||
Index("ix_video_url_format_id", "url", "format_id"),
|
||||
)
|
||||
|
||||
logs = relationship("DownloadLog", back_populates="video", lazy="select")
|
||||
|
||||
|
||||
class DownloadLog(Base):
|
||||
__tablename__ = "download_logs"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
video_id = Column(Integer, ForeignKey("videos.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
ip = Column(String(64), default="")
|
||||
user_agent = Column(Text, default="")
|
||||
browser = Column(String(64), default="") # Chrome / Firefox / Safari / Edge / …
|
||||
device = Column(String(32), default="") # desktop / mobile / tablet / bot
|
||||
downloaded_at = Column(DateTime, default=datetime.utcnow, index=True)
|
||||
|
||||
video = relationship("Video", back_populates="logs")
|
||||
|
||||
Reference in New Issue
Block a user