### 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>tags/v0.13.0
| try: | try: | ||||
| docs = DocumentService.get_thumbnails(doc_ids) | 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}) | return get_json_result(data={d["id"]: d["thumbnail"] for d in docs}) | ||||
| except Exception as e: | except Exception as e: | ||||
| return server_error_response(e) | return server_error_response(e) | 
| @classmethod | @classmethod | ||||
| @DB.connection_context() | @DB.connection_context() | ||||
| def get_thumbnails(cls, docids): | def get_thumbnails(cls, docids): | ||||
| fields = [cls.model.id, cls.model.thumbnail] | |||||
| fields = [cls.model.id, cls.model.kb_id, cls.model.thumbnail] | |||||
| return list(cls.model.select( | return list(cls.model.select( | ||||
| *fields).where(cls.model.id.in_(docids)).dicts()) | *fields).where(cls.model.id.in_(docids)).dicts()) | ||||
| doc_id = get_uuid() | doc_id = get_uuid() | ||||
| img = thumbnail_img(filename, blob) | img = thumbnail_img(filename, blob) | ||||
| thumbnail_location = f'thumbnail_{doc_id}.png' | |||||
| STORAGE_IMPL.put(kb.id, thumbnail_location, img) | |||||
| thumbnail_location = '' | |||||
| if img is not None: | |||||
| thumbnail_location = f'thumbnail_{doc_id}.png' | |||||
| STORAGE_IMPL.put(kb.id, thumbnail_location, img) | |||||
| doc = { | doc = { | ||||
| "id": doc_id, | "id": doc_id, | 
| }, [content, loading, t]); | }, [content, loading, t]); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| setDocumentIds(reference?.doc_aggs.map((x) => x.doc_id) ?? []); | |||||
| setDocumentIds(reference?.doc_aggs?.map((x) => x.doc_id) ?? []); | |||||
| }, [reference, setDocumentIds]); | }, [reference, setDocumentIds]); | ||||
| const handleDocumentButtonClick = useCallback( | const handleDocumentButtonClick = useCallback( |