mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-25 18:03:29 +08:00
### What problem does this PR solve? Fixes #15115. `GET /api/v1/documents/images/<image_id>` returned **Image not found** when the thumbnail storage object key contained hyphens (e.g. `page-1.png`). Document APIs build URLs as `{dataset_id}-{thumbnail}`, but `get_document_image()` used `image_id.split("-")` and required exactly two segments, so keys like `<kb_id>-page-1.png` were rejected even though the blob existed. This PR splits only on the first hyphen (`split("-", 1)`) and sets `Content-Type` from the object key extension via `CONTENT_TYPE_MAP` instead of hardcoding `image/JPEG`.
This commit is contained in:
@@ -563,6 +563,50 @@ class TestDocumentMetadataUnit:
|
||||
assert res["code"] == 500
|
||||
assert "image boom" in res["message"]
|
||||
|
||||
def test_get_document_image_hyphenated_object_key(self, document_app_module, monkeypatch):
|
||||
"""Hyphenated thumbnail keys are parsed with split('-', 1) and return correct MIME type."""
|
||||
module = document_app_module
|
||||
|
||||
class _Headers(dict):
|
||||
def set(self, key, value):
|
||||
self[key] = value
|
||||
|
||||
class _ImageResponse:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.headers = _Headers()
|
||||
|
||||
storage_calls = []
|
||||
|
||||
def _storage_get(bkt, nm):
|
||||
storage_calls.append((bkt, nm))
|
||||
return b"png-bytes"
|
||||
|
||||
async def fake_thread_pool_exec(fn, *args, **kwargs):
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
async def fake_make_response(data):
|
||||
return _ImageResponse(data)
|
||||
|
||||
monkeypatch.setattr(module, "thread_pool_exec", fake_thread_pool_exec)
|
||||
monkeypatch.setattr(module, "make_response", fake_make_response)
|
||||
monkeypatch.setattr(
|
||||
module.settings,
|
||||
"STORAGE_IMPL",
|
||||
SimpleNamespace(get=_storage_get),
|
||||
)
|
||||
|
||||
image_id = "kb12345678901234567890123456789012-page-1.png"
|
||||
res = _run(module.get_document_image(image_id))
|
||||
assert isinstance(res, _ImageResponse)
|
||||
assert storage_calls == [("kb12345678901234567890123456789012", "page-1.png")]
|
||||
assert res.headers["Content-Type"] == "image/png"
|
||||
|
||||
res = _run(module.get_document_image("only-one-part"))
|
||||
assert res["code"] == RetCode.DATA_ERROR
|
||||
assert "Image not found" in res["message"]
|
||||
|
||||
|
||||
class TestDocumentBatchChangeStatus:
|
||||
@pytest.mark.p2
|
||||
def test_change_status_partial_failure_matrix(self, WebApiAuth, add_dataset, ragflow_tmp_dir):
|
||||
|
||||
Reference in New Issue
Block a user