mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
file uploader
This commit is contained in:
parent
fd9b71c4d7
commit
f5d1f5a20a
|
@ -16,11 +16,12 @@ type Shape = {
|
|||
setFiles: (files: FileEntity[]) => void
|
||||
}
|
||||
|
||||
export const createFileStore = () => {
|
||||
export const createFileStore = (onChange?: (files: FileEntity[]) => void) => {
|
||||
return create<Shape>(set => ({
|
||||
files: [],
|
||||
setFiles: (files) => {
|
||||
set({ files })
|
||||
onChange?.(files)
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
@ -44,14 +45,16 @@ type FileProviderProps = {
|
|||
children: React.ReactNode
|
||||
isPublicAPI?: boolean
|
||||
url?: string
|
||||
onChange?: (files: FileEntity[]) => void
|
||||
}
|
||||
export const FileContextProvider = ({
|
||||
children,
|
||||
onChange,
|
||||
}: FileProviderProps) => {
|
||||
const storeRef = useRef<FileStore>()
|
||||
|
||||
if (!storeRef.current)
|
||||
storeRef.current = createFileStore()
|
||||
storeRef.current = createFileStore(onChange)
|
||||
|
||||
return (
|
||||
<FileContext.Provider value={storeRef.current}>
|
||||
|
|
|
@ -113,7 +113,12 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||
</div>
|
||||
)
|
||||
}
|
||||
<FileUploaderInAttachmentWrapper onChange={() => {}} />
|
||||
<FileUploaderInAttachmentWrapper onChange={files => onVisionFilesChange(files.filter(file => file.progress !== -1).map(fileItem => ({
|
||||
type: fileItem.fileType,
|
||||
transfer_method: fileItem.type,
|
||||
url: fileItem.url || '',
|
||||
upload_file_id: fileItem.fileId,
|
||||
})))} />
|
||||
{promptConfig.prompt_variables.length > 0 && (
|
||||
<div className='mt-4 h-[1px] bg-gray-100'></div>
|
||||
)}
|
||||
|
|
|
@ -159,7 +159,12 @@ const FormItem: FC<Props> = ({
|
|||
|
||||
{/* #TODO# file upload */}
|
||||
{(type === InputVarType.singleFile || type === InputVarType.multiFiles) && (
|
||||
<FileUploaderInAttachmentWrapper onChange={() => {}} />
|
||||
<FileUploaderInAttachmentWrapper onChange={files => onChange(files.filter(file => file.progress !== -1).map(fileItem => ({
|
||||
type: fileItem.fileType,
|
||||
transfer_method: fileItem.type,
|
||||
url: fileItem.url,
|
||||
upload_file_id: fileItem.fileId,
|
||||
})))} />
|
||||
)}
|
||||
{
|
||||
type === InputVarType.files && (
|
||||
|
|
Loading…
Reference in New Issue
Block a user