Repository navigation
fix(api): infer /documents/{id}/download Content-Type from filename when ext is omitted (#15052) - #15053
Conversation
…tted Align GET /documents/<id>/download with /preview: require access + load document, then derive extension and MIME from doc.name if the `ext` query parameter is absent. Keeps explicit ?ext= behavior for backward compatibility. Fixes infiniflow#15052.
📝 WalkthroughWalkthroughThe download endpoint now gates access via ChangesDocument download authorization and content-type inference
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15053 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…hen ext is omitted (#15052) (#15053) ## Summary - Align **GET `/api/v1/documents/<doc_id>/download`** with **`/preview`**: resolve extension and MIME type from the stored document name when the **`ext` query parameter is omitted**, instead of defaulting to `markdown`. - When **`?ext=`** is present, behavior stays the same as before (explicit extension / `Content-Type` mapping). - Enforce the same access + document lookup pattern as preview (**`accessible`** + **`get_by_id`**). - Extend unit tests for the no-`ext` PDF filename case. ## Test plan - [x] `uv run pytest test/testcases/test_web_api/test_document_app/test_document_metadata.py::TestDocumentMetadataUnit::test_download_attachment_success_and_exception_unit` - [x] Optional: `curl -sSI` against `/api/v1/documents/<pdf_doc_id>/download` without `ext` and confirm `Content-Type: application/pdf` Fixes #15052.
…lename when ext is omitted (#15052)" (#15138) Reverts infiniflow/ragflow#15053
Summary
/api/v1/documents/<doc_id>/downloadwith/preview: resolve extension and MIME type from the stored document name when theextquery parameter is omitted, instead of defaulting tomarkdown.?ext=is present, behavior stays the same as before (explicit extension /Content-Typemapping).accessible+get_by_id).extPDF filename case.Test plan
uv run pytest test/testcases/test_web_api/test_document_app/test_document_metadata.py::TestDocumentMetadataUnit::test_download_attachment_success_and_exception_unitcurl -sSIagainst/api/v1/documents/<pdf_doc_id>/downloadwithoutextand confirmContent-Type: application/pdfFixes #15052.