From 279dc5b89438ccee21fefbf4d55708004ff12501 Mon Sep 17 00:00:00 2001 From: Yuzhiran Dev Date: Mon, 18 May 2026 08:18:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20writer.py=20=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=20HTML=20=E6=9C=AA=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AF=BC=E8=87=B4=E9=A2=84=E8=A7=88=E5=92=8C=E5=90=88?= =?UTF-8?q?=E8=A7=84=E4=BC=98=E5=8C=96=E5=9D=87=E5=8F=96=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit save_html 在写文件后新增 save_article() 调用,将 HTML 持久化到 articles 表, 使预览 API 和 compliance_optimizer 能从 DB 正常读取文章内容 --- scripts/writer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/writer.py b/scripts/writer.py index eb76333..2c67099 100644 --- a/scripts/writer.py +++ b/scripts/writer.py @@ -7,7 +7,7 @@ PROJECT_ROOT = Path(__file__).parent.parent sys.path.insert(0, str(PROJECT_ROOT)) sys.path.insert(0, str(PROJECT_ROOT / 'platform' / 'backend')) -from db_helper import get_topic_by_id, update_topic_status +from db_helper import get_topic_by_id, update_topic_status, save_article try: from app.core.nvidia_client import call_llm HAVE_LLM = True @@ -424,6 +424,11 @@ class Writer: out_path = out_dir / filename out_path.write_text(html, encoding='utf-8') logger.info(f"HTML 生成: {out_path}") + try: + save_article(self.topic_id, platform, html) + logger.info(f"文章写入数据库: {platform}_{self.topic_id}") + except Exception as e: + logger.warning(f"数据库保存失败: {e}") return out_path def mark_draft(self):