fix: Fixed the issue of error reporting when uploading files in the chat box #2897 (#2898)

### 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:
balibabu
2024-10-18 17:21:12 +08:00
committed by GitHub
parent c760f058df
commit 526fcbbfde
6 changed files with 37 additions and 70 deletions

View File

@ -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 = ({
<Space>
{showUploadIcon && (
<Upload
// action={uploadUrl}
// fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
multiple={false}
// headers={{ [Authorization]: getAuthorization() }}
// data={{ conversation_id: conversationId }}
// method="post"
onRemove={handleRemove}
showUploadList={false}
beforeUpload={(file, fileList) => {
console.log('🚀 ~ beforeUpload:', fileList);
beforeUpload={() => {
return false;
}}
>
@ -283,17 +273,14 @@ const MessageInput = ({
<List.Item>
<Card className={styles.documentCard}>
<Flex gap={10} align="center">
{item.status === 'uploading' || !item.response ? (
{item.status === 'uploading' ? (
<Spin
indicator={
<LoadingOutlined style={{ fontSize: 24 }} spin />
}
/>
) : !getFileId(item) ? (
<InfoCircleOutlined
size={30}
// width={30}
></InfoCircleOutlined>
) : item.status === 'error' ? (
<InfoCircleOutlined size={30}></InfoCircleOutlined>
) : (
<FileIcon id={id} name={fileName}></FileIcon>
)}
@ -304,7 +291,7 @@ const MessageInput = ({
>
<b> {fileName}</b>
</Text>
{isUploadError(item) ? (
{item.status === 'error' ? (
t('uploadFailed')
) : (
<>