-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Refactor: migrate document thumbnails API #14344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
0418bce
431a399
42608a6
6f3bbba
5760685
3954d2e
00c529e
c45488e
7845a6f
d0401c1
3c0183a
b9757e0
464a94a
566ca80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -530,7 +530,7 @@ def list_docs(dataset_id, tenant_id): | |
| renamed_doc_list = [map_doc_keys(doc) for doc in docs] | ||
| for doc_item in renamed_doc_list: | ||
| if doc_item["thumbnail"] and not doc_item["thumbnail"].startswith(IMG_BASE64_PREFIX): | ||
| doc_item["thumbnail"] = f"/v1/document/image/{dataset_id}-{doc_item['thumbnail']}" | ||
| doc_item["thumbnail"] = f"/api/v1/documents/images/{dataset_id}-{doc_item['thumbnail']}" | ||
| if doc_item.get("source_type"): | ||
| doc_item["source_type"] = doc_item["source_type"].split("/")[0] | ||
| if doc_item["parser_config"].get("metadata"): | ||
|
|
@@ -979,6 +979,44 @@ async def update_metadata_config(tenant_id, dataset_id, document_id): | |
| return get_result(data=doc.to_dict()) | ||
|
|
||
|
|
||
| @manager.route("/thumbnails", methods=["GET"]) # noqa: F821 | ||
| def list_thumbnails(): | ||
| """ | ||
| Get thumbnails for documents. | ||
| --- | ||
| tags: | ||
| - Documents | ||
| parameters: | ||
| - in: query | ||
| name: doc_ids | ||
| type: array | ||
| required: true | ||
| description: List of document IDs to get thumbnails for. | ||
| responses: | ||
| 200: | ||
| description: Successfully retrieved thumbnails | ||
| 400: | ||
| description: Missing document IDs | ||
| """ | ||
| from api.constants import IMG_BASE64_PREFIX | ||
| from api.db.services.document_service import DocumentService | ||
|
|
||
| doc_ids = request.args.getlist("doc_ids") | ||
| if not doc_ids: | ||
| return get_json_result(data=False, message='Lack of "Document ID"', code=RetCode.ARGUMENT_ERROR) | ||
|
|
||
| try: | ||
| docs = DocumentService.get_thumbnails(doc_ids) | ||
|
|
||
| for doc_item in docs: | ||
| if doc_item["thumbnail"] and not doc_item["thumbnail"].startswith(IMG_BASE64_PREFIX): | ||
| doc_item["thumbnail"] = f"/v1/document/image/{doc_item['kb_id']}-{doc_item['thumbnail']}" | ||
|
|
||
| return get_json_result(data={d["id"]: d["thumbnail"] for d in docs}) | ||
| except Exception as e: | ||
| return server_error_response(e) | ||
|
Comment on lines
+1171
to
+1206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect the handler as it existed just before this PR's changes on the target branch.
git fetch origin main --depth=1 >/dev/null 2>&1 || true
git show origin/main:api/apps/document_app.py 2>/dev/null \
| awk '/@manager\.route\("\/thumbnails"/{flag=1} flag{print; if(/^def |^async def /){c++}; if(c>=1 && /^$/){exit}}'Repository: infiniflow/ragflow Length of output: 331 Add authentication and authorization to the The
Add 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| @manager.route("/datasets/<dataset_id>/documents/metadatas", methods=["PATCH"]) # noqa: F821 | ||
| @login_required | ||
| @add_tenant_id_to_kwargs | ||
|
|
@@ -1319,3 +1357,45 @@ def _run_sync(): | |
| except Exception as e: | ||
| logging.exception(e) | ||
| return get_error_data_result(message="Internal server error") | ||
|
|
||
|
|
||
| @manager.route("/documents/images/<image_id>", methods=["GET"]) # noqa: F821 | ||
| async def get_document_image(image_id): | ||
| """ | ||
| Get a document image by ID. | ||
| --- | ||
| tags: | ||
| - Documents | ||
| parameters: | ||
| - name: image_id | ||
| in: path | ||
| required: true | ||
| schema: | ||
| type: string | ||
| description: The image ID (format: bucket-name-image-name) | ||
| responses: | ||
| 200: | ||
| description: Image file | ||
| content: | ||
| image/jpeg: | ||
| schema: | ||
| type: string | ||
| format: binary | ||
| """ | ||
| try: | ||
| from quart import make_response | ||
|
|
||
| from common import settings | ||
| from common.misc_utils import thread_pool_exec | ||
| from api.utils.api_utils import get_data_error_result, server_error_response | ||
|
|
||
| arr = image_id.split("-") | ||
| if len(arr) != 2: | ||
| return get_data_error_result(message="Image not found.") | ||
| bkt, nm = image_id.split("-") | ||
| data = await thread_pool_exec(settings.STORAGE_IMPL.get, bkt, nm) | ||
| response = await make_response(data) | ||
| response.headers.set("Content-Type", "image/JPEG") | ||
| return response | ||
| except Exception as e: | ||
| return server_error_response(e) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.