Skip to content

Commit 2a86472

Browse files
chongchuanbingchongchuanbing
and
chongchuanbing
authored
fix chat and thumbnail bug (infiniflow#2803)
### What problem does this PR solve? 1. fix white screen issue when chat response 2. thumbnail bug when document not support ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --------- Co-authored-by: chongchuanbing <chongchuanbing@gmail.com>
1 parent 190eea7 commit 2a86472

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

api/apps/document_app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ def thumbnails():
238238

239239
try:
240240
docs = DocumentService.get_thumbnails(doc_ids)
241+
242+
for doc_item in docs:
243+
if doc_item['thumbnail'] and not doc_item['thumbnail'].startswith(IMG_BASE64_PREFIX):
244+
doc_item['thumbnail'] = f"/v1/document/image/{doc_item['kb_id']}-{doc_item['thumbnail']}"
245+
241246
return get_json_result(data={d["id"]: d["thumbnail"] for d in docs})
242247
except Exception as e:
243248
return server_error_response(e)

api/db/services/document_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def get_doc_id_by_doc_name(cls, doc_name):
268268
@classmethod
269269
@DB.connection_context()
270270
def get_thumbnails(cls, docids):
271-
fields = [cls.model.id, cls.model.thumbnail]
271+
fields = [cls.model.id, cls.model.kb_id, cls.model.thumbnail]
272272
return list(cls.model.select(
273273
*fields).where(cls.model.id.in_(docids)).dicts())
274274

api/db/services/file_service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,10 @@ def upload_document(self, kb, file_objs, user_id):
358358
doc_id = get_uuid()
359359

360360
img = thumbnail_img(filename, blob)
361-
thumbnail_location = f'thumbnail_{doc_id}.png'
362-
STORAGE_IMPL.put(kb.id, thumbnail_location, img)
361+
thumbnail_location = ''
362+
if img is not None:
363+
thumbnail_location = f'thumbnail_{doc_id}.png'
364+
STORAGE_IMPL.put(kb.id, thumbnail_location, img)
363365

364366
doc = {
365367
"id": doc_id,

web/src/pages/chat/markdown-content/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const MarkdownContent = ({
4545
}, [content, loading, t]);
4646

4747
useEffect(() => {
48-
setDocumentIds(reference?.doc_aggs.map((x) => x.doc_id) ?? []);
48+
setDocumentIds(reference?.doc_aggs?.map((x) => x.doc_id) ?? []);
4949
}, [reference, setDocumentIds]);
5050

5151
const handleDocumentButtonClick = useCallback(

0 commit comments

Comments
 (0)