fix: validate article summary extracted path input

This commit is contained in:
root
2026-04-11 23:04:13 +08:00
parent c58d8114cd
commit 52ce6bfdf5
2 changed files with 15 additions and 6 deletions
@@ -76,6 +76,17 @@ def _load_result(job_id: str) -> dict[str, Any] | None:
return json.loads(path.read_text(encoding="utf-8-sig"))
def _validate_article_summary_extracted_path(extracted_path: Path) -> None:
if not extracted_path.exists():
raise FileNotFoundError(f"extracted_path does not exist: {extracted_path}")
if extracted_path.is_dir():
raise ValueError(
"extracted_path must be a JSON file, not a directory. "
"Pass a single extracted file like outputs/freshrss/rerun/<run-id>/extracted/item-01.extracted.json, "
"or a batch extracted JSON file."
)
def start_article_summary_job(
*,
extracted_path: Path,
@@ -87,8 +98,7 @@ def start_article_summary_job(
llm_model: str | None = None,
llm_api_url: str | None = None,
) -> dict[str, Any]:
if not extracted_path.exists():
raise FileNotFoundError(f"extracted_path does not exist: {extracted_path}")
_validate_article_summary_extracted_path(extracted_path)
if not selected_ids:
raise ValueError("selected_ids must not be empty")
@@ -166,8 +176,7 @@ def run_article_summary_job(*, job_id: str) -> dict[str, Any]:
extracted_path = Path(input_payload["extracted_path"])
output_dir = Path(input_payload["output_dir"])
selected_ids = list(input_payload["selected_ids"])
if not extracted_path.exists():
raise FileNotFoundError(f"extracted_path does not exist: {extracted_path}")
_validate_article_summary_extracted_path(extracted_path)
if not selected_ids:
raise ValueError("selected_ids must not be empty")
store.finish_stage(