file uploader

This commit is contained in:
StyleZhang 2024-09-18 16:50:53 +08:00
parent fd9b71c4d7
commit f5d1f5a20a
3 changed files with 17 additions and 4 deletions

View File

@ -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}>

View File

@ -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>
)}

View File

@ -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 && (