feat: AI改写面板样式优化、封面图片显示、max_tokens调整至8192

This commit is contained in:
wangwuww111
2026-03-16 16:35:59 +08:00
parent 253bc4aed2
commit d111f1a2cf
5 changed files with 1352 additions and 61 deletions

View File

@@ -678,7 +678,7 @@ async def get_drafts(
):
"""获取用户的草稿列表"""
result = await db.execute(
select(StoryDraft, Story.title.label("story_title"))
select(StoryDraft, Story.title.label("story_title"), Story.cover_url)
.join(Story, StoryDraft.story_id == Story.id)
.where(StoryDraft.user_id == userId)
.order_by(StoryDraft.created_at.desc())
@@ -688,6 +688,15 @@ async def get_drafts(
for row in result:
draft = row[0]
story_title = row[1]
story_cover_url = row[2]
# AI创作类型优先使用 ai_nodes 中的封面
cover_url = story_cover_url or ""
if draft.draft_type == "create" and draft.ai_nodes:
ai_cover = draft.ai_nodes.get("coverUrl") if isinstance(draft.ai_nodes, dict) else None
if ai_cover:
cover_url = ai_cover
drafts.append({
"id": draft.id,
"storyId": draft.story_id,
@@ -698,6 +707,7 @@ async def get_drafts(
"isRead": draft.is_read,
"publishedToCenter": draft.published_to_center,
"draftType": draft.draft_type or "rewrite",
"coverUrl": cover_url,
"createdAt": draft.created_at.strftime("%Y-%m-%d %H:%M") if draft.created_at else "",
"completedAt": draft.completed_at.strftime("%Y-%m-%d %H:%M") if draft.completed_at else None
})
@@ -745,18 +755,25 @@ async def get_published_drafts(
draftType: Optional[str] = None,
db: AsyncSession = Depends(get_db)
):
"""获取已发布到创作中心的草稿列表"""
query = select(StoryDraft, Story.title.label('story_title')).join(
"""获取草稿列表
- rewrite/continue 类型:返回已发布到创作中心的
- create 类型:返回所有已完成的(用户可选择发布)
"""
query = select(StoryDraft, Story.title.label('story_title'), Story.cover_url).join(
Story, StoryDraft.story_id == Story.id
).where(
StoryDraft.user_id == userId,
StoryDraft.published_to_center == True,
StoryDraft.status == DraftStatus.completed
)
# 按类型筛选
if draftType:
query = query.where(StoryDraft.draft_type == draftType)
# create 类型不需要 published_to_center 限制
if draftType != 'create':
query = query.where(StoryDraft.published_to_center == True)
else:
query = query.where(StoryDraft.published_to_center == True)
query = query.order_by(StoryDraft.created_at.desc())
@@ -764,14 +781,25 @@ async def get_published_drafts(
rows = result.all()
drafts = []
for draft, story_title in rows:
for draft, story_title, story_cover_url in rows:
# AI创作类型优先使用 ai_nodes 中的封面
cover_url = story_cover_url or ""
if draft.draft_type == "create" and draft.ai_nodes:
ai_cover = draft.ai_nodes.get("coverUrl") if isinstance(draft.ai_nodes, dict) else None
if ai_cover:
cover_url = ai_cover
drafts.append({
"id": draft.id,
"story_id": draft.story_id, # 添加 story_id 字段
"storyId": draft.story_id,
"storyTitle": story_title or "未知故事",
"title": draft.title or "",
"userPrompt": draft.user_prompt,
"draftType": draft.draft_type or "rewrite",
"status": draft.status.value if draft.status else "completed",
"published_to_center": draft.published_to_center,
"coverUrl": cover_url,
"createdAt": draft.created_at.strftime("%Y-%m-%d %H:%M") if draft.created_at else ""
})