Phase3: 三平台封面图生成
- cover_generator.py: Pillow生成知乎/微信/小红书封面图(渐变背景+标题) - 知乎 1200×630 蓝调, 微信 900×500 绿调, 小红书 1080×1440 红调 - creator.py 流水线增加 cover_generator 作为最终回退 - db_helper.py 新增 save_cover_to_article - main.py 挂载 /automation/images 静态目录 - articles.py preview 接口返回 images 字段 - topics.html 预览dialog展示封面图
This commit is contained in:
@@ -259,6 +259,27 @@ def save_article(topic_id: str, platform: str, html_content: str, db: Optional[S
|
||||
if close_db:
|
||||
db.close()
|
||||
|
||||
def save_cover_to_article(topic_id: str, platform: str, cover_path: str, db: Optional[Session] = None):
|
||||
"""保存封面图路径到 article.images 字段"""
|
||||
close_db = False
|
||||
if db is None:
|
||||
db = SessionLocal()
|
||||
close_db = True
|
||||
try:
|
||||
from app.models import Article
|
||||
article_id = f"{platform}_{topic_id}"
|
||||
article = db.query(Article).filter(Article.id == article_id).first()
|
||||
if article:
|
||||
images = article.images or {}
|
||||
images["cover"] = cover_path
|
||||
article.images = images
|
||||
db.commit()
|
||||
except Exception:
|
||||
db.rollback()
|
||||
finally:
|
||||
if close_db:
|
||||
db.close()
|
||||
|
||||
def get_article(topic_id: str, platform: str, db: Optional[Session] = None) -> Optional[Dict]:
|
||||
"""从 articles 表获取文章 HTML"""
|
||||
close_db = False
|
||||
|
||||
Reference in New Issue
Block a user