Fix SSE route dependency and align architecture docs

This commit is contained in:
ash66
2026-05-18 16:32:42 +08:00
parent 86b9ac806a
commit 3f69cad404
149 changed files with 4786 additions and 5957 deletions

View File

@@ -0,0 +1,38 @@
"""Local parser adapter for the migrated backend architecture."""
from __future__ import annotations
from pathlib import Path
from app.domain.documents import DocumentParser, ParsedDocument
from app.services.parser.docx_parser import parse_docx_to_markdown
from app.services.parser.pdf_parser import parse_pdf_to_markdown
class LocalDocumentParser(DocumentParser):
"""Adapt the existing local PDF/DOCX parsers to the new parser port."""
parser_name = "local_markdown_parser"
def parse(self, *, file_path: str, doc_id: str, doc_name: str) -> ParsedDocument:
suffix = Path(file_path).suffix.lower()
if suffix == ".pdf":
markdown_text = parse_pdf_to_markdown(file_path)
elif suffix in {".docx", ".doc"}:
markdown_text = parse_docx_to_markdown(file_path)
else:
raise ValueError(f"不支持的文件类型: {suffix}")
if not markdown_text.strip():
raise ValueError("本地解析完成但未提取到有效文本")
return ParsedDocument(
doc_id=doc_id,
doc_name=doc_name,
structure_nodes=[],
semantic_blocks=[],
vector_chunks=[],
parser_name=self.parser_name,
raw_text=markdown_text,
metadata={"source": "local_parser", "file_suffix": suffix},
)