balibabu
commited on
Commit
·
a4c4dfd
1
Parent(s):
e6cd231
fix: Fixed the issue of error reporting when uploading files in the chat box #2897 (#2898)
Browse files### 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):
web/src/components/message-input/index.tsx
CHANGED
|
@@ -52,11 +52,6 @@ const getFileIds = (fileList: UploadFile[]) => {
|
|
| 52 |
return ids;
|
| 53 |
};
|
| 54 |
|
| 55 |
-
const isUploadError = (file: UploadFile) => {
|
| 56 |
-
const retcode = get(file, 'response.retcode');
|
| 57 |
-
return typeof retcode === 'number' && retcode !== 0;
|
| 58 |
-
};
|
| 59 |
-
|
| 60 |
const isUploadSuccess = (file: UploadFile) => {
|
| 61 |
const retcode = get(file, 'response.retcode');
|
| 62 |
return typeof retcode === 'number' && retcode === 0;
|
|
@@ -121,7 +116,7 @@ const MessageInput = ({
|
|
| 121 |
const creatingRet = await createConversationBeforeUploadDocument(
|
| 122 |
file.name,
|
| 123 |
);
|
| 124 |
-
if (creatingRet
|
| 125 |
nextConversationId = creatingRet.data.id;
|
| 126 |
}
|
| 127 |
}
|
|
@@ -133,6 +128,7 @@ const MessageInput = ({
|
|
| 133 |
});
|
| 134 |
return [...list];
|
| 135 |
});
|
|
|
|
| 136 |
const ret = await uploadAndParseDocument({
|
| 137 |
conversationId: nextConversationId,
|
| 138 |
fileList: [file],
|
|
@@ -217,18 +213,12 @@ const MessageInput = ({
|
|
| 217 |
<Space>
|
| 218 |
{showUploadIcon && (
|
| 219 |
<Upload
|
| 220 |
-
// action={uploadUrl}
|
| 221 |
-
// fileList={fileList}
|
| 222 |
onPreview={handlePreview}
|
| 223 |
onChange={handleChange}
|
| 224 |
multiple={false}
|
| 225 |
-
// headers={{ [Authorization]: getAuthorization() }}
|
| 226 |
-
// data={{ conversation_id: conversationId }}
|
| 227 |
-
// method="post"
|
| 228 |
onRemove={handleRemove}
|
| 229 |
showUploadList={false}
|
| 230 |
-
beforeUpload={(
|
| 231 |
-
console.log('🚀 ~ beforeUpload:', fileList);
|
| 232 |
return false;
|
| 233 |
}}
|
| 234 |
>
|
|
@@ -283,17 +273,14 @@ const MessageInput = ({
|
|
| 283 |
<List.Item>
|
| 284 |
<Card className={styles.documentCard}>
|
| 285 |
<Flex gap={10} align="center">
|
| 286 |
-
{item.status === 'uploading'
|
| 287 |
<Spin
|
| 288 |
indicator={
|
| 289 |
<LoadingOutlined style={{ fontSize: 24 }} spin />
|
| 290 |
}
|
| 291 |
/>
|
| 292 |
-
) :
|
| 293 |
-
<InfoCircleOutlined
|
| 294 |
-
size={30}
|
| 295 |
-
// width={30}
|
| 296 |
-
></InfoCircleOutlined>
|
| 297 |
) : (
|
| 298 |
<FileIcon id={id} name={fileName}></FileIcon>
|
| 299 |
)}
|
|
@@ -304,7 +291,7 @@ const MessageInput = ({
|
|
| 304 |
>
|
| 305 |
<b> {fileName}</b>
|
| 306 |
</Text>
|
| 307 |
-
{
|
| 308 |
t('uploadFailed')
|
| 309 |
) : (
|
| 310 |
<>
|
|
|
|
| 52 |
return ids;
|
| 53 |
};
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
const isUploadSuccess = (file: UploadFile) => {
|
| 56 |
const retcode = get(file, 'response.retcode');
|
| 57 |
return typeof retcode === 'number' && retcode === 0;
|
|
|
|
| 116 |
const creatingRet = await createConversationBeforeUploadDocument(
|
| 117 |
file.name,
|
| 118 |
);
|
| 119 |
+
if (creatingRet?.retcode === 0) {
|
| 120 |
nextConversationId = creatingRet.data.id;
|
| 121 |
}
|
| 122 |
}
|
|
|
|
| 128 |
});
|
| 129 |
return [...list];
|
| 130 |
});
|
| 131 |
+
|
| 132 |
const ret = await uploadAndParseDocument({
|
| 133 |
conversationId: nextConversationId,
|
| 134 |
fileList: [file],
|
|
|
|
| 213 |
<Space>
|
| 214 |
{showUploadIcon && (
|
| 215 |
<Upload
|
|
|
|
|
|
|
| 216 |
onPreview={handlePreview}
|
| 217 |
onChange={handleChange}
|
| 218 |
multiple={false}
|
|
|
|
|
|
|
|
|
|
| 219 |
onRemove={handleRemove}
|
| 220 |
showUploadList={false}
|
| 221 |
+
beforeUpload={() => {
|
|
|
|
| 222 |
return false;
|
| 223 |
}}
|
| 224 |
>
|
|
|
|
| 273 |
<List.Item>
|
| 274 |
<Card className={styles.documentCard}>
|
| 275 |
<Flex gap={10} align="center">
|
| 276 |
+
{item.status === 'uploading' ? (
|
| 277 |
<Spin
|
| 278 |
indicator={
|
| 279 |
<LoadingOutlined style={{ fontSize: 24 }} spin />
|
| 280 |
}
|
| 281 |
/>
|
| 282 |
+
) : item.status === 'error' ? (
|
| 283 |
+
<InfoCircleOutlined size={30}></InfoCircleOutlined>
|
|
|
|
|
|
|
|
|
|
| 284 |
) : (
|
| 285 |
<FileIcon id={id} name={fileName}></FileIcon>
|
| 286 |
)}
|
|
|
|
| 291 |
>
|
| 292 |
<b> {fileName}</b>
|
| 293 |
</Text>
|
| 294 |
+
{item.status === 'error' ? (
|
| 295 |
t('uploadFailed')
|
| 296 |
) : (
|
| 297 |
<>
|
web/src/hooks/document-hooks.ts
CHANGED
|
@@ -422,17 +422,21 @@ export const useUploadAndParseDocument = (uploadMethod: string) => {
|
|
| 422 |
conversationId: string;
|
| 423 |
fileList: UploadFile[];
|
| 424 |
}) => {
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
return data?.data;
|
|
|
|
|
|
|
| 433 |
}
|
| 434 |
-
const data = await chatService.uploadAndParseExternal(formData);
|
| 435 |
-
return data?.data;
|
| 436 |
},
|
| 437 |
});
|
| 438 |
|
|
|
|
| 422 |
conversationId: string;
|
| 423 |
fileList: UploadFile[];
|
| 424 |
}) => {
|
| 425 |
+
try {
|
| 426 |
+
const formData = new FormData();
|
| 427 |
+
formData.append('conversation_id', conversationId);
|
| 428 |
+
fileList.forEach((file: UploadFile) => {
|
| 429 |
+
formData.append('file', file as any);
|
| 430 |
+
});
|
| 431 |
+
if (uploadMethod === 'upload_and_parse') {
|
| 432 |
+
const data = await kbService.upload_and_parse(formData);
|
| 433 |
+
return data?.data;
|
| 434 |
+
}
|
| 435 |
+
const data = await chatService.uploadAndParseExternal(formData);
|
| 436 |
return data?.data;
|
| 437 |
+
} catch (error) {
|
| 438 |
+
console.log('🚀 ~ useUploadAndParseDocument ~ error:', error);
|
| 439 |
}
|
|
|
|
|
|
|
| 440 |
},
|
| 441 |
});
|
| 442 |
|
web/src/pages/chat/hooks.ts
CHANGED
|
@@ -582,14 +582,18 @@ export const useSendButtonDisabled = (value: string) => {
|
|
| 582 |
export const useCreateConversationBeforeUploadDocument = () => {
|
| 583 |
const { setConversation } = useSetConversation();
|
| 584 |
const { dialogId } = useGetChatSearchParams();
|
|
|
|
| 585 |
|
| 586 |
const createConversationBeforeUploadDocument = useCallback(
|
| 587 |
async (message: string) => {
|
| 588 |
-
const
|
|
|
|
|
|
|
| 589 |
|
| 590 |
-
|
|
|
|
| 591 |
},
|
| 592 |
-
[setConversation],
|
| 593 |
);
|
| 594 |
|
| 595 |
return {
|
|
|
|
| 582 |
export const useCreateConversationBeforeUploadDocument = () => {
|
| 583 |
const { setConversation } = useSetConversation();
|
| 584 |
const { dialogId } = useGetChatSearchParams();
|
| 585 |
+
const { getConversationIsNew } = useSetChatRouteParams();
|
| 586 |
|
| 587 |
const createConversationBeforeUploadDocument = useCallback(
|
| 588 |
async (message: string) => {
|
| 589 |
+
const isNew = getConversationIsNew();
|
| 590 |
+
if (isNew === 'true') {
|
| 591 |
+
const data = await setConversation(message, true);
|
| 592 |
|
| 593 |
+
return data;
|
| 594 |
+
}
|
| 595 |
},
|
| 596 |
+
[setConversation, getConversationIsNew],
|
| 597 |
);
|
| 598 |
|
| 599 |
return {
|
web/src/pages/chat/markdown-content/index.less
CHANGED
|
@@ -43,3 +43,8 @@
|
|
| 43 |
}
|
| 44 |
}
|
| 45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
}
|
| 45 |
}
|
| 46 |
+
|
| 47 |
+
.fileThumbnail {
|
| 48 |
+
display: inline-block;
|
| 49 |
+
max-width: 40px;
|
| 50 |
+
}
|
web/src/pages/chat/markdown-content/index.tsx
CHANGED
|
@@ -118,7 +118,11 @@ const MarkdownContent = ({
|
|
| 118 |
{documentId && (
|
| 119 |
<Flex gap={'small'}>
|
| 120 |
{fileThumbnail ? (
|
| 121 |
-
<img
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
) : (
|
| 123 |
<SvgIcon
|
| 124 |
name={`file-icon/${fileExtension}`}
|
|
|
|
| 118 |
{documentId && (
|
| 119 |
<Flex gap={'small'}>
|
| 120 |
{fileThumbnail ? (
|
| 121 |
+
<img
|
| 122 |
+
src={fileThumbnail}
|
| 123 |
+
alt=""
|
| 124 |
+
className={styles.fileThumbnail}
|
| 125 |
+
/>
|
| 126 |
) : (
|
| 127 |
<SvgIcon
|
| 128 |
name={`file-icon/${fileExtension}`}
|
web/src/services/knowledge-service.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import api from '@/utils/api';
|
| 2 |
import registerServer from '@/utils/register-server';
|
| 3 |
import request from '@/utils/request';
|
| 4 |
-
import pureRequest from 'umi-request';
|
| 5 |
|
| 6 |
const {
|
| 7 |
create_kb,
|
|
@@ -25,7 +24,6 @@ const {
|
|
| 25 |
retrieval_test,
|
| 26 |
document_rename,
|
| 27 |
document_run,
|
| 28 |
-
get_document_file,
|
| 29 |
document_upload,
|
| 30 |
web_crawl,
|
| 31 |
knowledge_graph,
|
|
@@ -145,39 +143,4 @@ const methods = {
|
|
| 145 |
|
| 146 |
const kbService = registerServer<keyof typeof methods>(methods, request);
|
| 147 |
|
| 148 |
-
export const getDocumentFile = (documentId: string) => {
|
| 149 |
-
return pureRequest(get_document_file + '/' + documentId, {
|
| 150 |
-
responseType: 'blob',
|
| 151 |
-
method: 'get',
|
| 152 |
-
parseResponse: false,
|
| 153 |
-
// getResponse: true,
|
| 154 |
-
})
|
| 155 |
-
.then((res) => {
|
| 156 |
-
const x = res.headers.get('content-disposition');
|
| 157 |
-
console.info(res);
|
| 158 |
-
console.info(x);
|
| 159 |
-
return res.blob();
|
| 160 |
-
})
|
| 161 |
-
.then((res) => {
|
| 162 |
-
// const objectURL = URL.createObjectURL(res);
|
| 163 |
-
|
| 164 |
-
// let btn = document.createElement('a');
|
| 165 |
-
|
| 166 |
-
// btn.download = '文件名.pdf';
|
| 167 |
-
|
| 168 |
-
// btn.href = objectURL;
|
| 169 |
-
|
| 170 |
-
// btn.click();
|
| 171 |
-
|
| 172 |
-
// URL.revokeObjectURL(objectURL);
|
| 173 |
-
|
| 174 |
-
// btn = null;
|
| 175 |
-
|
| 176 |
-
return res;
|
| 177 |
-
})
|
| 178 |
-
.catch((err) => {
|
| 179 |
-
console.info(err);
|
| 180 |
-
});
|
| 181 |
-
};
|
| 182 |
-
|
| 183 |
export default kbService;
|
|
|
|
| 1 |
import api from '@/utils/api';
|
| 2 |
import registerServer from '@/utils/register-server';
|
| 3 |
import request from '@/utils/request';
|
|
|
|
| 4 |
|
| 5 |
const {
|
| 6 |
create_kb,
|
|
|
|
| 24 |
retrieval_test,
|
| 25 |
document_rename,
|
| 26 |
document_run,
|
|
|
|
| 27 |
document_upload,
|
| 28 |
web_crawl,
|
| 29 |
knowledge_graph,
|
|
|
|
| 143 |
|
| 144 |
const kbService = registerServer<keyof typeof methods>(methods, request);
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
export default kbService;
|