fc4ebb7de0
后端: - 新建 mjk_cover_backgrounds 表(Alembic e02c96e264d9) - CoverBackground模型/CRUD/Schema/API(GET /cover-backgrounds?script_code=) 前端: - ScriptCreation保存categoryCode到store和meta.json - CoverDesign从API获取背景图,替换bg-config.json - 修复useEffect不响应categoryCode变化的bug 其他: - 删除Rust遗留的generate_cover_image命令和burn_ass_subtitle_to_image函数
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
封面背景图 API
|
|
===============
|
|
|
|
按脚本大类返回封面背景图列表。
|
|
"""
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db.session import get_db
|
|
from app.models.cover_background import CoverBackground
|
|
from app.schemas.common import ApiResponse, success_response
|
|
from app.schemas.cover_background import CoverBackgroundItem
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/cover-backgrounds", response_model=ApiResponse[list[CoverBackgroundItem]])
|
|
async def list_cover_backgrounds(
|
|
script_code: str,
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""
|
|
根据脚本大类 code 获取封面背景图列表
|
|
|
|
如 script_code=bk 返回装修避坑大类下的所有封面背景图。
|
|
"""
|
|
result = await db.execute(
|
|
select(CoverBackground)
|
|
.where(CoverBackground.script_code == script_code)
|
|
.where(CoverBackground.status == "active")
|
|
.order_by(CoverBackground.sort_order.asc())
|
|
)
|
|
|
|
items = [
|
|
CoverBackgroundItem(
|
|
id=m.id,
|
|
script_code=m.script_code,
|
|
title=m.title,
|
|
url=m.url,
|
|
sort_order=m.sort_order,
|
|
)
|
|
for m in result.scalars().all()
|
|
]
|
|
|
|
return success_response(data=items, message="获取成功")
|