fix: harden edge cases in cloud upload, local doc_type, and PDF utilities

- cloud.py: replace bare resp['doc_id'] with .get() + CloudAPIError
- local.py: case-insensitive doc_type comparison for .PDF extensions
- utils.py: add else branch to get_pdf_name for non-str/BytesIO inputs
- utils.py: raise ValueError in get_page_tokens when PyMuPDF path invalid
This commit is contained in:
Ray 2026-07-18 23:44:45 +08:00
parent ccc8b43bb7
commit 3a1727b578
3 changed files with 8 additions and 2 deletions

View file

@ -214,7 +214,9 @@ class CloudBackend:
with open(file_path, "rb") as f:
resp = self._request("POST", "/doc/", files={"file": f}, data=data)
doc_id = resp["doc_id"]
doc_id = resp.get("doc_id")
if not doc_id:
raise CloudAPIError("Cloud API upload response missing 'doc_id'")
# Poll until indexing completes. The cloud API signals readiness via
# status == "completed"; retrieval_ready is not a reliable indicator.

View file

@ -230,7 +230,7 @@ class LocalBackend:
# stripped (if_add_node_text=False, the default). Reachable only for a
# custom StorageEngine that doesn't cache pages (the built-in
# SQLiteStorage always does).
if doc["doc_type"] == "pdf":
if doc["doc_type"].lower() == "pdf":
return get_pdf_page_content(doc["file_path"], page_nums)
else:
parser = self._resolve_parser(doc["file_path"])

View file

@ -748,6 +748,8 @@ def get_pdf_name(pdf_path):
meta = pdf_reader.metadata
pdf_name = meta.title if meta and meta.title else 'Untitled'
pdf_name = sanitize_filename(pdf_name)
else:
pdf_name = os.path.basename(str(pdf_path))
return pdf_name
@ -820,6 +822,8 @@ def get_page_tokens(pdf_path, model=None, pdf_parser="PyPDF2"):
doc = pymupdf.open(stream=pdf_stream, filetype="pdf")
elif isinstance(pdf_path, str) and os.path.isfile(pdf_path) and pdf_path.lower().endswith(".pdf"):
doc = pymupdf.open(pdf_path)
else:
raise ValueError(f"Invalid pdf_path for PyMuPDF: {pdf_path!r}")
page_list = []
for page in doc:
page_text = page.get_text()