Skip to content

Recover missing local PDFs for Agent Papers catalog - #29

Draft
znsoftm wants to merge 2 commits into
mainfrom
cursor/papers-pdf-recover-e7d3
Draft

znsoftm wants to merge 2 commits into
mainfrom
cursor/papers-pdf-recover-e7d3

Conversation

@znsoftm

@znsoftm znsoftm commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

When an Agent Papers catalog entry is an arXiv paper but has no file under pdfs/ (UI: “无本地 PDF” / “No local PDF”), operators can recover it without a full sync.

Endpoint

POST /papers/pdf/recover

  • Single: { "id": "2609.03747" } (also accepts arxiv_id)
  • Batch: { "all_missing": true } — walks catalog entries with no local PDF and an arxiv_id or pdf_url; concurrency capped at 2
  • Success (single): { "ok": true, "paper": { has_local, local_pdf, ... }, "already_present": false }
  • Failure: JSON { "ok": false, "error": "...", "code": "fetch"|"papers"|"bad_request" } with a clear message (arXiv HTTP 404, HTML-only, network, not in catalog)
  • Idempotent: a valid PDF already on disk refreshes manifest metadata and returns already_present without re-downloading

Auth: same as /papers and /settings — Hub global admin cookie, admin Bearer, or operator SEARCH_TOKEN (including ?token= on the page and its XHRs). Unauthenticated POST is JSON 401.

URL strategy: try the stored pdf_url, then https://arxiv.org/pdf/{id}.pdf (and the un-suffixed form). Follows redirects. Rejects non-PDF bodies (HTML 404 / withdrawn / HTML-only). Does not mark has_local unless a real %PDF file is written.

Persistence: writes pdfs/, updates manifest.json (pdf_path, download_status, optional page_count), invalidates the in-memory catalog snapshot, and best-effort patches papers.db via python3 sqlite if that file exists.

This tree has no hf_daily.go / import-translate pipeline. Download checks match the existing Python download_pdf helper (magic bytes, arXiv ?download=1 retry). auto_translate is not present here, so recover does not enqueue translation.

UI

On /papers, when can_manage (authenticated catalog) and !has_local and arxiv_id or pdf_url is set, a 恢复 PDF / Recover PDF button appears next to the muted “无本地 PDF” label. Click calls the API, shows progress/error on that card, and swaps in View/Download without a full page reload. A toolbar 恢复缺失 PDF action runs the batch path.

Tests

internal/api/papers_recover_test.go: fake PDF server success, arXiv 404, HTML-only, already-present file, corrupt re-download, batch counts, auth 401, optional SQLite update.

Open in Web Open in Cursor 

cursoragent and others added 2 commits September 17, 2026 06:43
Operators can POST /papers/pdf/recover to re-download an arXiv PDF
into pdfs/, refresh manifest/DB/catalog fields, and use a Recover PDF
button on /papers when the file is missing.

Co-authored-by: Daniel <znsoft@163.com>
SEARCH_TOKEN already authenticates GET /papers via the query string,
but the catalog and recover XHRs omitted it and 401'd.

Co-authored-by: Daniel <znsoft@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants