Download app/models/play_history.py from binhugg2/api: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/binhugg2/api/resolve/main/app/models/play_history.py
- Command line
-
hf download hf://spaces/binhugg2/api/app/models/play_history.py
-
curl -L -o play_history.py https://huggingface.co/spaces/binhugg2/api/resolve/main/app/models/play_history.py
1.4 kB
| from datetime import datetime | |
| from sqlalchemy import DateTime, Index, Integer, String, func | |
| from sqlalchemy.orm import Mapped, mapped_column | |
| from app.database import Base | |
| class PlayHistory(Base): | |
| __tablename__ = "play_history" | |
| id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) | |
| user_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="用户ID") | |
| vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="影片ID") | |
| source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") | |
| episode: Mapped[str | None] = mapped_column(String(50), comment="集名") | |
| play_url: Mapped[str] = mapped_column(String, nullable=False, comment="播放地址") | |
| progress: Mapped[int] = mapped_column(Integer, default=0, comment="播放进度(秒)") | |
| duration: Mapped[int] = mapped_column(Integer, default=0, comment="总时长(秒)") | |
| created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) | |
| updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) | |
| __table_args__ = ( | |
| # 历史列表:按用户 + 时间倒序 | |
| Index("ix_play_history_user_updated", "user_id", "updated_at"), | |
| # 更新播放进度:user_id + vod_id 定位记录 | |
| Index("ix_play_history_user_vod", "user_id", "vod_id"), | |
| ) | |