feat: refactor summarizer and PDF extraction pipeline
- Split summarizer into summary_generator and summary_persister modules - Refactor pdf_image_extractor to two-phase pipeline with PicoDet layout detection - Add layout_detector service for PicoDet-S_layout_3cls integration - Add exceptions module with ConflictError and NotFoundError - Improve admin dashboard with better statistics and task management - Add design review document with system optimization suggestions - Add new tests for crawler, pdf_downloader, pipeline, and summary_utils - Update dependencies and configuration - Clean up dead code and improve error handling
This commit is contained in:
+5
-23
@@ -2,12 +2,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.exceptions import NotFoundError
|
||||
from app.services.user_data import (
|
||||
get_note,
|
||||
save_note,
|
||||
@@ -37,9 +38,6 @@ def bookmark_toggle(arxiv_id: str, request: Request, db: Session = Depends(get_d
|
||||
"""切换收藏状态。支持 HTMX 局部刷新和 JSON 响应。"""
|
||||
result = toggle_bookmark(db, arxiv_id)
|
||||
|
||||
if "error" in result:
|
||||
raise HTTPException(status_code=404, detail=result["error"])
|
||||
|
||||
# HTMX 请求 → 返回 HTML 片段
|
||||
if request.headers.get("HX-Request"):
|
||||
star = "★" if result["bookmarked"] else "☆"
|
||||
@@ -66,18 +64,7 @@ def reading_status_update(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""更新阅读状态。"""
|
||||
result = set_reading_status(db, arxiv_id, body.status)
|
||||
|
||||
if "error" in result:
|
||||
if result["error"] == "not_found":
|
||||
raise HTTPException(status_code=404, detail="Paper not found")
|
||||
elif result["error"] == "invalid_status":
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail=f"Invalid status. Valid: {result['valid']}",
|
||||
)
|
||||
|
||||
return result
|
||||
return set_reading_status(db, arxiv_id, body.status)
|
||||
|
||||
|
||||
# ── 笔记 ──────────────────────────────────────────────────────────────
|
||||
@@ -88,16 +75,11 @@ def note_get(arxiv_id: str, db: Session = Depends(get_db)):
|
||||
"""获取笔记。"""
|
||||
result = get_note(db, arxiv_id)
|
||||
if result is None:
|
||||
raise HTTPException(status_code=404, detail="Paper not found")
|
||||
raise NotFoundError(f"Paper not found: {arxiv_id}")
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/note/{arxiv_id}")
|
||||
def note_save(arxiv_id: str, body: NoteRequest, db: Session = Depends(get_db)):
|
||||
"""保存笔记。"""
|
||||
result = save_note(db, arxiv_id, body.content)
|
||||
|
||||
if "error" in result:
|
||||
raise HTTPException(status_code=404, detail=result["error"])
|
||||
|
||||
return result
|
||||
return save_note(db, arxiv_id, body.content)
|
||||
|
||||
Reference in New Issue
Block a user