feat(web): remote file add api
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-03-17 14:22:25
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-20 15:44:48
|
||||
* @Last Modified time: 2026-03-23 17:42:38
|
||||
*/
|
||||
// Toolbar component for chat input area, supporting file upload, audio recording, and variable configuration
|
||||
import { useRef, forwardRef, useImperativeHandle, type ReactNode, useEffect } from 'react'
|
||||
@@ -18,6 +18,7 @@ import type { FeaturesConfigForm } from '@/views/ApplicationConfig/types'
|
||||
import type { UploadFileListModalRef } from '@/views/Conversation/types'
|
||||
import type { VariableConfigModalRef } from '@/views/Workflow/types'
|
||||
import type { Variable } from '@/views/Workflow/components/Properties/VariableList/types'
|
||||
import { getFileInfoByUrl } from '@/api/fileStorage';
|
||||
|
||||
// Exposed methods via ref for parent components to access/set form state
|
||||
export interface ChatToolbarRef {
|
||||
@@ -103,9 +104,33 @@ const ChatToolbar = forwardRef<ChatToolbarRef, ChatToolbarProps>(({
|
||||
// Merge a batch of files (e.g. from remote URL modal) into the file list
|
||||
const addFileList = (list?: any[]) => {
|
||||
if (!list?.length) return
|
||||
const files = [...(queryValues?.files || []), ...list]
|
||||
const uploadingList = list.map(f => ({ ...f, status: 'uploading' }))
|
||||
const files = [...(queryValues?.files || []), ...uploadingList]
|
||||
form.setFieldValue('files', files)
|
||||
onFilesChange?.(files)
|
||||
|
||||
uploadingList.forEach(file => {
|
||||
getFileInfoByUrl(file.url)
|
||||
.then((res) => {
|
||||
const { file_name, file_size, content_type } = res as { file_name: string; file_size: number; content_type: string; }
|
||||
const current: any[] = form.getFieldValue('files') || []
|
||||
const updated = current.map(f => f.uid === file.uid ? {
|
||||
...f,
|
||||
status: 'done',
|
||||
name: file_name,
|
||||
size: file_size,
|
||||
type: content_type,
|
||||
} : f)
|
||||
form.setFieldValue('files', updated)
|
||||
onFilesChange?.(updated)
|
||||
})
|
||||
.catch(() => {
|
||||
const current: any[] = form.getFieldValue('files') || []
|
||||
const updated = current.map(f => f.uid === file.uid ? { ...f, status: 'error' } : f)
|
||||
form.setFieldValue('files', updated)
|
||||
onFilesChange?.(updated)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Persist variable values from the config modal and notify parent
|
||||
|
||||
Reference in New Issue
Block a user