chongcb chongchuanbing commited on
Commit
7b36ea6
·
1 Parent(s): 1500cac

fix chat and thumbnail bug (#2803)

Browse files

### 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 <[email protected]>

api/apps/document_app.py CHANGED
@@ -238,6 +238,11 @@ def thumbnails():
238
 
239
  try:
240
  docs = DocumentService.get_thumbnails(doc_ids)
 
 
 
 
 
241
  return get_json_result(data={d["id"]: d["thumbnail"] for d in docs})
242
  except Exception as e:
243
  return server_error_response(e)
 
238
 
239
  try:
240
  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
+
246
  return get_json_result(data={d["id"]: d["thumbnail"] for d in docs})
247
  except Exception as e:
248
  return server_error_response(e)
api/db/services/document_service.py CHANGED
@@ -268,7 +268,7 @@ class DocumentService(CommonService):
268
  @classmethod
269
  @DB.connection_context()
270
  def get_thumbnails(cls, docids):
271
- fields = [cls.model.id, cls.model.thumbnail]
272
  return list(cls.model.select(
273
  *fields).where(cls.model.id.in_(docids)).dicts())
274
 
 
268
  @classmethod
269
  @DB.connection_context()
270
  def get_thumbnails(cls, docids):
271
+ fields = [cls.model.id, cls.model.kb_id, cls.model.thumbnail]
272
  return list(cls.model.select(
273
  *fields).where(cls.model.id.in_(docids)).dicts())
274
 
api/db/services/file_service.py CHANGED
@@ -358,8 +358,10 @@ class FileService(CommonService):
358
  doc_id = get_uuid()
359
 
360
  img = thumbnail_img(filename, blob)
361
- thumbnail_location = f'thumbnail_{doc_id}.png'
362
- STORAGE_IMPL.put(kb.id, thumbnail_location, img)
 
 
363
 
364
  doc = {
365
  "id": doc_id,
 
358
  doc_id = get_uuid()
359
 
360
  img = thumbnail_img(filename, blob)
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)
365
 
366
  doc = {
367
  "id": doc_id,
web/src/pages/chat/markdown-content/index.tsx CHANGED
@@ -45,7 +45,7 @@ const MarkdownContent = ({
45
  }, [content, loading, t]);
46
 
47
  useEffect(() => {
48
- setDocumentIds(reference?.doc_aggs.map((x) => x.doc_id) ?? []);
49
  }, [reference, setDocumentIds]);
50
 
51
  const handleDocumentButtonClick = useCallback(
 
45
  }, [content, loading, t]);
46
 
47
  useEffect(() => {
48
+ setDocumentIds(reference?.doc_aggs?.map((x) => x.doc_id) ?? []);
49
  }, [reference, setDocumentIds]);
50
 
51
  const handleDocumentButtonClick = useCallback(