diff --git a/web/src/components/message-input/index.tsx b/web/src/components/message-input/index.tsx index fb9ea4c9df..d786869c0b 100644 --- a/web/src/components/message-input/index.tsx +++ b/web/src/components/message-input/index.tsx @@ -52,11 +52,6 @@ const getFileIds = (fileList: UploadFile[]) => { return ids; }; -const isUploadError = (file: UploadFile) => { - const retcode = get(file, 'response.retcode'); - return typeof retcode === 'number' && retcode !== 0; -}; - const isUploadSuccess = (file: UploadFile) => { const retcode = get(file, 'response.retcode'); return typeof retcode === 'number' && retcode === 0; @@ -121,7 +116,7 @@ const MessageInput = ({ const creatingRet = await createConversationBeforeUploadDocument( file.name, ); - if (creatingRet.retcode === 0) { + if (creatingRet?.retcode === 0) { nextConversationId = creatingRet.data.id; } } @@ -133,6 +128,7 @@ const MessageInput = ({ }); return [...list]; }); + const ret = await uploadAndParseDocument({ conversationId: nextConversationId, fileList: [file], @@ -217,18 +213,12 @@ const MessageInput = ({ {showUploadIcon && ( { - console.log('๐Ÿš€ ~ beforeUpload:', fileList); + beforeUpload={() => { return false; }} > @@ -283,17 +273,14 @@ const MessageInput = ({ - {item.status === 'uploading' || !item.response ? ( + {item.status === 'uploading' ? ( } /> - ) : !getFileId(item) ? ( - + ) : item.status === 'error' ? ( + ) : ( )} @@ -304,7 +291,7 @@ const MessageInput = ({ > {fileName} - {isUploadError(item) ? ( + {item.status === 'error' ? ( t('uploadFailed') ) : ( <> diff --git a/web/src/hooks/document-hooks.ts b/web/src/hooks/document-hooks.ts index 8c952e2587..1ee4384dd2 100644 --- a/web/src/hooks/document-hooks.ts +++ b/web/src/hooks/document-hooks.ts @@ -422,17 +422,21 @@ export const useUploadAndParseDocument = (uploadMethod: string) => { conversationId: string; fileList: UploadFile[]; }) => { - const formData = new FormData(); - formData.append('conversation_id', conversationId); - fileList.forEach((file: UploadFile) => { - formData.append('file', file as any); - }); - if (uploadMethod === 'upload_and_parse') { - const data = await kbService.upload_and_parse(formData); + try { + const formData = new FormData(); + formData.append('conversation_id', conversationId); + fileList.forEach((file: UploadFile) => { + formData.append('file', file as any); + }); + if (uploadMethod === 'upload_and_parse') { + const data = await kbService.upload_and_parse(formData); + return data?.data; + } + const data = await chatService.uploadAndParseExternal(formData); return data?.data; + } catch (error) { + console.log('๐Ÿš€ ~ useUploadAndParseDocument ~ error:', error); } - const data = await chatService.uploadAndParseExternal(formData); - return data?.data; }, }); diff --git a/web/src/pages/chat/hooks.ts b/web/src/pages/chat/hooks.ts index 7444990dcc..bc0348a8a5 100644 --- a/web/src/pages/chat/hooks.ts +++ b/web/src/pages/chat/hooks.ts @@ -582,14 +582,18 @@ export const useSendButtonDisabled = (value: string) => { export const useCreateConversationBeforeUploadDocument = () => { const { setConversation } = useSetConversation(); const { dialogId } = useGetChatSearchParams(); + const { getConversationIsNew } = useSetChatRouteParams(); const createConversationBeforeUploadDocument = useCallback( async (message: string) => { - const data = await setConversation(message, true); + const isNew = getConversationIsNew(); + if (isNew === 'true') { + const data = await setConversation(message, true); - return data; + return data; + } }, - [setConversation], + [setConversation, getConversationIsNew], ); return { diff --git a/web/src/pages/chat/markdown-content/index.less b/web/src/pages/chat/markdown-content/index.less index caa208017f..66f9c6a6f1 100644 --- a/web/src/pages/chat/markdown-content/index.less +++ b/web/src/pages/chat/markdown-content/index.less @@ -43,3 +43,8 @@ } } } + +.fileThumbnail { + display: inline-block; + max-width: 40px; +} diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsx index db3d1504e6..156a8950db 100644 --- a/web/src/pages/chat/markdown-content/index.tsx +++ b/web/src/pages/chat/markdown-content/index.tsx @@ -118,7 +118,11 @@ const MarkdownContent = ({ {documentId && ( {fileThumbnail ? ( - + ) : ( (methods, request); -export const getDocumentFile = (documentId: string) => { - return pureRequest(get_document_file + '/' + documentId, { - responseType: 'blob', - method: 'get', - parseResponse: false, - // getResponse: true, - }) - .then((res) => { - const x = res.headers.get('content-disposition'); - console.info(res); - console.info(x); - return res.blob(); - }) - .then((res) => { - // const objectURL = URL.createObjectURL(res); - - // let btn = document.createElement('a'); - - // btn.download = 'ๆ–‡ไปถๅ.pdf'; - - // btn.href = objectURL; - - // btn.click(); - - // URL.revokeObjectURL(objectURL); - - // btn = null; - - return res; - }) - .catch((err) => { - console.info(err); - }); -}; - export default kbService;