把“章节正文 + 图片”从 chapters 单表/JSON 结构,重构为“章节 chapter + 段落 section + 图片 memoir_images 独立表”的新数据模型,同时联动修改接口、PDF 导出、异步任务、迁移脚本、测试,以及修复 Android 端聊天列表显示问题。 (#9)
* refactor: 表结构重构,新增段落section和图片image新表 * fix: fix android app import error * refactor: 重构文件名 * fix: 优化提示词 * fix: 消息气泡显示位置异常问题 --------- Co-authored-by: yangshilin <2157598560@qq.com>
This commit is contained in:
@@ -112,14 +112,20 @@ async def export_pdf(
|
||||
if book.user_id != current_user.id:
|
||||
raise HTTPException(status_code=403, detail="无权导出此回忆录")
|
||||
|
||||
# 获取所有 active 章节
|
||||
# 获取所有 active 章节并预加载 sections(供 PDF 按段渲染)
|
||||
from database.models import Chapter
|
||||
stmt = select(Chapter).where(
|
||||
Chapter.user_id == current_user.id,
|
||||
Chapter.is_active == True
|
||||
).order_by(Chapter.order_index)
|
||||
from sqlalchemy.orm import joinedload
|
||||
stmt = (
|
||||
select(Chapter)
|
||||
.where(
|
||||
Chapter.user_id == current_user.id,
|
||||
Chapter.is_active == True,
|
||||
)
|
||||
.options(joinedload(Chapter.sections))
|
||||
.order_by(Chapter.order_index)
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
chapters = result.scalars().all()
|
||||
chapters = result.unique().scalars().all()
|
||||
|
||||
# 生成 PDF
|
||||
pdf_bytes = await pdf_service.generate_pdf(book, chapters)
|
||||
|
||||
Reference in New Issue
Block a user