This commit is contained in:
lz_db
2026-10-25 11:46:44 +08:00
parent 893dfed0ed
commit 494f667719
63 changed files with 5213 additions and 239 deletions
+20 -3
View File
@@ -155,7 +155,7 @@ async def dashboard(db: AsyncSession) -> dict:
# ---------- 视频审核 / 管理 ----------
def _video_item(video: Video, author: User | None) -> dict:
def _video_item(video: Video, author: User | None, source_name: str = "") -> dict:
return {
"video_id": video.id,
"title": video.title,
@@ -164,6 +164,8 @@ def _video_item(video: Video, author: User | None) -> dict:
"video_url": video.video_url,
"duration": video.duration,
"category_id": video.category_id or 0,
"source_id": video.source_id or 0,
"source_name": source_name,
"series_id": video.series_id,
"episode_no": video.episode_no,
"status": video.status,
@@ -207,7 +209,7 @@ async def list_pending_videos(db: AsyncSession, page: int, page_size: int) -> di
async def list_videos(
db: AsyncSession, keyword: str | None, status: int | None, author_id: int | None,
page: int, page_size: int,
page: int, page_size: int, source_id: int | None = None,
) -> dict:
"""视频列表(11.25)"""
stmt = select(Video)
@@ -218,12 +220,27 @@ async def list_videos(
stmt = stmt.where(Video.status == status)
if author_id is not None:
stmt = stmt.where(Video.user_id == author_id)
if source_id is not None:
stmt = stmt.where(Video.source_id == source_id)
total = (await db.execute(select(func.count()).select_from(stmt.subquery()))).scalar() or 0
rows = (await db.execute(
stmt.order_by(Video.id.desc()).offset((page - 1) * page_size).limit(page_size)
)).scalars().all()
authors = await _authors_map(db, rows)
return {"total": total, "list": [_video_item(v, authors.get(v.user_id)) for v in rows]}
names = await source_names_map(db, {v.source_id for v in rows})
return {"total": total,
"list": [_video_item(v, authors.get(v.user_id), names.get(v.source_id, "")) for v in rows]}
async def source_names_map(db: AsyncSession, ids: set[int]) -> dict[int, str]:
"""来源 id → 名称"""
from app.models.video import Source
ids = {i for i in ids if i}
if not ids:
return {}
rows = (await db.execute(select(Source.id, Source.name).where(Source.id.in_(ids)))).all()
return {r.id: r.name for r in rows}
async def review_video(