From fd9b71c4d73974d3bb4a6ce1f85956a5386bbcc0 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Wed, 18 Sep 2024 16:36:31 +0800 Subject: [PATCH] file uploader --- .../base/chat/chat/chat-input-area/index.tsx | 123 ++++++++++-------- .../base/file-uploader/constants.ts | 1 + .../components/base/file-uploader/hooks.ts | 14 +- .../components/base/file-uploader/store.tsx | 13 +- .../components/base/file-uploader/types.ts | 4 + .../components/base/file-uploader/utils.ts | 11 ++ 6 files changed, 106 insertions(+), 60 deletions(-) create mode 100644 web/app/components/base/file-uploader/constants.ts diff --git a/web/app/components/base/chat/chat/chat-input-area/index.tsx b/web/app/components/base/chat/chat/chat-input-area/index.tsx index f96d15b8ac..7f6510665b 100644 --- a/web/app/components/base/chat/chat/chat-input-area/index.tsx +++ b/web/app/components/base/chat/chat/chat-input-area/index.tsx @@ -1,5 +1,4 @@ import { - memo, useCallback, useRef, useState, @@ -16,11 +15,15 @@ import { useTextAreaHeight } from './hooks' import Operation from './operation' import cn from '@/utils/classnames' import { FileListInChatInput } from '@/app/components/base/file-uploader' -import { FileContextProvider } from '@/app/components/base/file-uploader/store' +import { + FileContextProvider, + useStore, +} from '@/app/components/base/file-uploader/store' import VoiceInput from '@/app/components/base/voice-input' import { useToastContext } from '@/app/components/base/toast' import FeatureBar from '@/app/components/base/features/new-feature-panel/feature-bar' import type { FileUpload } from '@/app/components/base/features/types' +import { TransferMethod } from '@/types/app' type ChatInputAreaProps = { showFeatureBar?: boolean @@ -55,15 +58,27 @@ const ChatInputArea = ({ const [query, setQuery] = useState('') const isUseInputMethod = useRef(false) const [showVoiceInput, setShowVoiceInput] = useState(false) + const files = useStore(s => s.files) + const setFiles = useStore(s => s.setFiles) const handleSend = () => { if (onSend) { + if (files.find(item => item.type === TransferMethod.local_file && !item.fileStorageId)) { + notify({ type: 'info', message: t('appDebug.errorMessage.waitForImgUpload') }) + return + } if (!query || !query.trim()) { notify({ type: 'info', message: t('appAnnotation.errorMessage.queryRequired') }) return } - onSend(query) + onSend(query, files.filter(file => file.progress !== -1).map(fileItem => ({ + type: fileItem.fileType, + transfer_method: fileItem.type, + url: fileItem.url || '', + upload_file_id: fileItem.fileStorageId || '', + }))) setQuery('') + setFiles([]) } } @@ -103,64 +118,70 @@ const ChatInputArea = ({ ) return ( - {}}> - <> -
-
- -
-
-
- {query} -
-