mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-09-25 16:16:01 +00:00
### What problem does this PR solve? fix: Fixed the issue of error reporting when uploading files in the chat box #2897 ### 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):
This commit is contained in:
parent
c760f058df
commit
526fcbbfde
@ -52,11 +52,6 @@ const getFileIds = (fileList: UploadFile[]) => {
|
|||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isUploadError = (file: UploadFile) => {
|
|
||||||
const retcode = get(file, 'response.retcode');
|
|
||||||
return typeof retcode === 'number' && retcode !== 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isUploadSuccess = (file: UploadFile) => {
|
const isUploadSuccess = (file: UploadFile) => {
|
||||||
const retcode = get(file, 'response.retcode');
|
const retcode = get(file, 'response.retcode');
|
||||||
return typeof retcode === 'number' && retcode === 0;
|
return typeof retcode === 'number' && retcode === 0;
|
||||||
@ -121,7 +116,7 @@ const MessageInput = ({
|
|||||||
const creatingRet = await createConversationBeforeUploadDocument(
|
const creatingRet = await createConversationBeforeUploadDocument(
|
||||||
file.name,
|
file.name,
|
||||||
);
|
);
|
||||||
if (creatingRet.retcode === 0) {
|
if (creatingRet?.retcode === 0) {
|
||||||
nextConversationId = creatingRet.data.id;
|
nextConversationId = creatingRet.data.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +128,7 @@ const MessageInput = ({
|
|||||||
});
|
});
|
||||||
return [...list];
|
return [...list];
|
||||||
});
|
});
|
||||||
|
|
||||||
const ret = await uploadAndParseDocument({
|
const ret = await uploadAndParseDocument({
|
||||||
conversationId: nextConversationId,
|
conversationId: nextConversationId,
|
||||||
fileList: [file],
|
fileList: [file],
|
||||||
@ -217,18 +213,12 @@ const MessageInput = ({
|
|||||||
<Space>
|
<Space>
|
||||||
{showUploadIcon && (
|
{showUploadIcon && (
|
||||||
<Upload
|
<Upload
|
||||||
// action={uploadUrl}
|
|
||||||
// fileList={fileList}
|
|
||||||
onPreview={handlePreview}
|
onPreview={handlePreview}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
// headers={{ [Authorization]: getAuthorization() }}
|
|
||||||
// data={{ conversation_id: conversationId }}
|
|
||||||
// method="post"
|
|
||||||
onRemove={handleRemove}
|
onRemove={handleRemove}
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
beforeUpload={(file, fileList) => {
|
beforeUpload={() => {
|
||||||
console.log('🚀 ~ beforeUpload:', fileList);
|
|
||||||
return false;
|
return false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -283,17 +273,14 @@ const MessageInput = ({
|
|||||||
<List.Item>
|
<List.Item>
|
||||||
<Card className={styles.documentCard}>
|
<Card className={styles.documentCard}>
|
||||||
<Flex gap={10} align="center">
|
<Flex gap={10} align="center">
|
||||||
{item.status === 'uploading' || !item.response ? (
|
{item.status === 'uploading' ? (
|
||||||
<Spin
|
<Spin
|
||||||
indicator={
|
indicator={
|
||||||
<LoadingOutlined style={{ fontSize: 24 }} spin />
|
<LoadingOutlined style={{ fontSize: 24 }} spin />
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : !getFileId(item) ? (
|
) : item.status === 'error' ? (
|
||||||
<InfoCircleOutlined
|
<InfoCircleOutlined size={30}></InfoCircleOutlined>
|
||||||
size={30}
|
|
||||||
// width={30}
|
|
||||||
></InfoCircleOutlined>
|
|
||||||
) : (
|
) : (
|
||||||
<FileIcon id={id} name={fileName}></FileIcon>
|
<FileIcon id={id} name={fileName}></FileIcon>
|
||||||
)}
|
)}
|
||||||
@ -304,7 +291,7 @@ const MessageInput = ({
|
|||||||
>
|
>
|
||||||
<b> {fileName}</b>
|
<b> {fileName}</b>
|
||||||
</Text>
|
</Text>
|
||||||
{isUploadError(item) ? (
|
{item.status === 'error' ? (
|
||||||
t('uploadFailed')
|
t('uploadFailed')
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
@ -422,17 +422,21 @@ export const useUploadAndParseDocument = (uploadMethod: string) => {
|
|||||||
conversationId: string;
|
conversationId: string;
|
||||||
fileList: UploadFile[];
|
fileList: UploadFile[];
|
||||||
}) => {
|
}) => {
|
||||||
const formData = new FormData();
|
try {
|
||||||
formData.append('conversation_id', conversationId);
|
const formData = new FormData();
|
||||||
fileList.forEach((file: UploadFile) => {
|
formData.append('conversation_id', conversationId);
|
||||||
formData.append('file', file as any);
|
fileList.forEach((file: UploadFile) => {
|
||||||
});
|
formData.append('file', file as any);
|
||||||
if (uploadMethod === 'upload_and_parse') {
|
});
|
||||||
const data = await kbService.upload_and_parse(formData);
|
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;
|
return data?.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log('🚀 ~ useUploadAndParseDocument ~ error:', error);
|
||||||
}
|
}
|
||||||
const data = await chatService.uploadAndParseExternal(formData);
|
|
||||||
return data?.data;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -582,14 +582,18 @@ export const useSendButtonDisabled = (value: string) => {
|
|||||||
export const useCreateConversationBeforeUploadDocument = () => {
|
export const useCreateConversationBeforeUploadDocument = () => {
|
||||||
const { setConversation } = useSetConversation();
|
const { setConversation } = useSetConversation();
|
||||||
const { dialogId } = useGetChatSearchParams();
|
const { dialogId } = useGetChatSearchParams();
|
||||||
|
const { getConversationIsNew } = useSetChatRouteParams();
|
||||||
|
|
||||||
const createConversationBeforeUploadDocument = useCallback(
|
const createConversationBeforeUploadDocument = useCallback(
|
||||||
async (message: string) => {
|
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 {
|
return {
|
||||||
|
@ -43,3 +43,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fileThumbnail {
|
||||||
|
display: inline-block;
|
||||||
|
max-width: 40px;
|
||||||
|
}
|
||||||
|
@ -118,7 +118,11 @@ const MarkdownContent = ({
|
|||||||
{documentId && (
|
{documentId && (
|
||||||
<Flex gap={'small'}>
|
<Flex gap={'small'}>
|
||||||
{fileThumbnail ? (
|
{fileThumbnail ? (
|
||||||
<img src={fileThumbnail} alt="" />
|
<img
|
||||||
|
src={fileThumbnail}
|
||||||
|
alt=""
|
||||||
|
className={styles.fileThumbnail}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<SvgIcon
|
<SvgIcon
|
||||||
name={`file-icon/${fileExtension}`}
|
name={`file-icon/${fileExtension}`}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import api from '@/utils/api';
|
import api from '@/utils/api';
|
||||||
import registerServer from '@/utils/register-server';
|
import registerServer from '@/utils/register-server';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import pureRequest from 'umi-request';
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
create_kb,
|
create_kb,
|
||||||
@ -25,7 +24,6 @@ const {
|
|||||||
retrieval_test,
|
retrieval_test,
|
||||||
document_rename,
|
document_rename,
|
||||||
document_run,
|
document_run,
|
||||||
get_document_file,
|
|
||||||
document_upload,
|
document_upload,
|
||||||
web_crawl,
|
web_crawl,
|
||||||
knowledge_graph,
|
knowledge_graph,
|
||||||
@ -145,39 +143,4 @@ const methods = {
|
|||||||
|
|
||||||
const kbService = registerServer<keyof typeof methods>(methods, request);
|
const kbService = registerServer<keyof typeof methods>(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;
|
export default kbService;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user