feat: 深色主题UI、错误分类、批量抓取、健康度筛选
- 修复 datetime 时区不一致导致所有API 500错误的问题 - Feeds/Dashboard 页面改为深色表格主题,高对比度文字 - 添加错误类型自动分类(URL失效/被拒绝/超时/DNS失败/SSL错误等12种) - 新增"下次抓取时间"列,从APScheduler获取 - 新增健康度筛选下拉,修复分页后过滤失效的bug - "全部抓取"改为同步并发执行,基于当前筛选条件获取所有匹配源 - 新增数据库自动迁移机制,处理增量列变更 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,8 @@ from pydantic import BaseModel, HttpUrl
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
from models import Feed
|
||||
from rss_fetcher import discover_feed_url, fetch_and_store_feed
|
||||
from scheduler import add_feed_job, remove_feed_job
|
||||
from rss_fetcher import discover_feed_url, fetch_and_store_feed, fetch_all_feeds
|
||||
from scheduler import add_feed_job, remove_feed_job, get_feed_next_run
|
||||
|
||||
router = APIRouter(prefix="/feeds", tags=["feeds"])
|
||||
|
||||
@@ -55,9 +55,10 @@ def list_feeds(
|
||||
category: Optional[str] = None,
|
||||
search: Optional[str] = None,
|
||||
is_active: Optional[bool] = None,
|
||||
health_status: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""获取 RSS 源列表,支持分页、分类筛选、搜索"""
|
||||
"""获取 RSS 源列表,支持分页、分类筛选、搜索、健康度筛选"""
|
||||
query = db.query(Feed)
|
||||
|
||||
if category:
|
||||
@@ -70,10 +71,22 @@ def list_feeds(
|
||||
)
|
||||
|
||||
total = query.count()
|
||||
feeds = query.order_by(Feed.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
# 健康度是计算字段,需要在 Python 中过滤
|
||||
if health_status:
|
||||
all_feeds = query.order_by(Feed.created_at.desc()).all()
|
||||
matched = []
|
||||
for feed in all_feeds:
|
||||
if feed.health_status() == health_status:
|
||||
matched.append(feed)
|
||||
total = len(matched)
|
||||
feeds = matched[skip:skip + limit]
|
||||
else:
|
||||
feeds = query.order_by(Feed.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
results = []
|
||||
for feed in feeds:
|
||||
next_run = get_feed_next_run(feed.id)
|
||||
data = {
|
||||
"id": feed.id,
|
||||
"url": feed.url,
|
||||
@@ -84,10 +97,13 @@ def list_feeds(
|
||||
"fetch_interval_minutes": feed.fetch_interval_minutes,
|
||||
"last_fetch_at": feed.last_fetch_at.isoformat() if feed.last_fetch_at else None,
|
||||
"last_fetch_status": feed.last_fetch_status,
|
||||
"last_error": feed.last_error,
|
||||
"error_type": feed.error_type,
|
||||
"success_count": feed.success_count,
|
||||
"fail_count": feed.fail_count,
|
||||
"article_count": feed.article_count,
|
||||
"health_status": feed.health_status(),
|
||||
"next_fetch_time": next_run.isoformat() if next_run else None,
|
||||
"created_at": feed.created_at.isoformat(),
|
||||
}
|
||||
results.append(data)
|
||||
@@ -210,6 +226,24 @@ def delete_feed(feed_id: int, db: Session = Depends(get_db)):
|
||||
return {"message": "RSS 源已删除"}
|
||||
|
||||
|
||||
class BatchFetchRequest(BaseModel):
|
||||
feed_ids: List[int]
|
||||
|
||||
|
||||
@router.post("/batch-fetch")
|
||||
def batch_fetch(data: BatchFetchRequest):
|
||||
"""批量抓取(并发同步执行,等待结果返回)"""
|
||||
results = fetch_all_feeds(data.feed_ids)
|
||||
success = sum(1 for r in results if r.get("success"))
|
||||
fail = len(results) - success
|
||||
return {
|
||||
"message": f"完成:{success} 个成功,{fail} 个失败",
|
||||
"total": len(results),
|
||||
"success": success,
|
||||
"fail": fail,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{feed_id}/fetch")
|
||||
def trigger_fetch(feed_id: int, db: Session = Depends(get_db)):
|
||||
"""手动触发抓取"""
|
||||
|
||||
Reference in New Issue
Block a user