233e23016c
- 文章 HTML 存储从文件系统迁移至 articles 表,删除 releases 目录 - 合规审查从 DB 读取 HTML,审查结果写回 DB,通过后自动推进至待发布 - 新增 todayCount 筛选按钮,与系统概览统计数据一致 - 全屏预览修复:提升 z-index 超过侧边栏,添加退出全屏/关闭按钮 - 统一 '优化' → '审查' 命名,消除前后端术语不一致 - 调度器创作完成后自动触发审查(生成 → 审查 → 待发布) - 清理旧备份/调试文件、过期大纲和研究笔记
46 lines
2.0 KiB
Python
46 lines
2.0 KiB
Python
from fastapi import APIRouter, HTTPException, Query, Depends
|
|
from sqlalchemy.orm import Session
|
|
from pathlib import Path
|
|
import os
|
|
from datetime import datetime, date
|
|
|
|
from ..database import get_db
|
|
from ..models import User, Article
|
|
from .auth import get_current_user
|
|
|
|
router = APIRouter(prefix="/api/articles", tags=["articles"])
|
|
|
|
@router.get("/drafts")
|
|
def list_drafts(topic_id: str = None, current_user: User = Depends(get_current_user), db: Session = Depends(get_db)):
|
|
"""从 articles 表列出草稿"""
|
|
query = db.query(Article)
|
|
if topic_id:
|
|
query = query.filter(Article.topic_id == topic_id)
|
|
articles = query.order_by(Article.created_at.desc()).all()
|
|
result = {}
|
|
for a in articles:
|
|
result.setdefault(a.platform, []).append({"id": a.id, "topic_id": a.topic_id, "status": a.status})
|
|
return {"articles": result}
|
|
|
|
@router.get("/{topic_id}/preview")
|
|
def preview_article(topic_id: str, platform: str = "zhihu", current_user: User = Depends(get_current_user), db: Session = Depends(get_db)):
|
|
"""从 articles 表预览某选题的 HTML 内容"""
|
|
article_id = f"{platform}_{topic_id}"
|
|
article = db.query(Article).filter(Article.id == article_id).first()
|
|
if not article or not article.html_content:
|
|
raise HTTPException(status_code=404, detail=f"Article not found for {topic_id} on {platform}")
|
|
return {"topic_id": topic_id, "platform": platform, "html": article.html_content}
|
|
|
|
@router.get("/optimization-report")
|
|
def get_optimization_report(publish_date: str = None, current_user: User = Depends(get_current_user)):
|
|
"""获取合规优化报告"""
|
|
if not publish_date:
|
|
publish_date = date.today().isoformat()
|
|
PROJECT_ROOT = Path('/root/openclaw-workspace/projects/yu-zhi-ran')
|
|
report_path = PROJECT_ROOT / "automation" / "data" / "drafts" / publish_date / "optimization_report.json"
|
|
if not report_path.exists():
|
|
raise HTTPException(status_code=404, detail="No optimization report for this date")
|
|
report = report_path.read_text(encoding='utf-8')
|
|
import json
|
|
return json.loads(report)
|