mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
fix: upload limit in knowledge
This commit is contained in:
@ -19,8 +19,6 @@ import { IS_CE_EDITION } from '@/config'
|
|||||||
import { Theme } from '@/types/app'
|
import { Theme } from '@/types/app'
|
||||||
import useTheme from '@/hooks/use-theme'
|
import useTheme from '@/hooks/use-theme'
|
||||||
|
|
||||||
const FILES_NUMBER_LIMIT = 20
|
|
||||||
|
|
||||||
type IFileUploaderProps = {
|
type IFileUploaderProps = {
|
||||||
fileList: FileItem[]
|
fileList: FileItem[]
|
||||||
titleClassName?: string
|
titleClassName?: string
|
||||||
@ -72,6 +70,7 @@ const FileUploader = ({
|
|||||||
const fileUploadConfig = useMemo(() => fileUploadConfigResponse ?? {
|
const fileUploadConfig = useMemo(() => fileUploadConfigResponse ?? {
|
||||||
file_size_limit: 15,
|
file_size_limit: 15,
|
||||||
batch_count_limit: 5,
|
batch_count_limit: 5,
|
||||||
|
batch_upload_limit: 5,
|
||||||
}, [fileUploadConfigResponse])
|
}, [fileUploadConfigResponse])
|
||||||
|
|
||||||
const fileListRef = useRef<FileItem[]>([])
|
const fileListRef = useRef<FileItem[]>([])
|
||||||
@ -121,10 +120,10 @@ const FileUploader = ({
|
|||||||
data: formData,
|
data: formData,
|
||||||
onprogress: onProgress,
|
onprogress: onProgress,
|
||||||
}, false, undefined, '?source=datasets')
|
}, false, undefined, '?source=datasets')
|
||||||
.then((res: File) => {
|
.then((res) => {
|
||||||
const completeFile = {
|
const completeFile = {
|
||||||
fileID: fileItem.fileID,
|
fileID: fileItem.fileID,
|
||||||
file: res,
|
file: res as unknown as File,
|
||||||
progress: -1,
|
progress: -1,
|
||||||
}
|
}
|
||||||
const index = fileListRef.current.findIndex(item => item.fileID === fileItem.fileID)
|
const index = fileListRef.current.findIndex(item => item.fileID === fileItem.fileID)
|
||||||
@ -163,11 +162,12 @@ const FileUploader = ({
|
|||||||
}, [fileUploadConfig, uploadBatchFiles])
|
}, [fileUploadConfig, uploadBatchFiles])
|
||||||
|
|
||||||
const initialUpload = useCallback((files: File[]) => {
|
const initialUpload = useCallback((files: File[]) => {
|
||||||
|
const filesCountLimit = fileUploadConfig.batch_upload_limit
|
||||||
if (!files.length)
|
if (!files.length)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if (files.length + fileList.length > FILES_NUMBER_LIMIT && !IS_CE_EDITION) {
|
if (files.length + fileList.length > filesCountLimit && !IS_CE_EDITION) {
|
||||||
notify({ type: 'error', message: t('datasetCreation.stepOne.uploader.validation.filesNumber', { filesNumber: FILES_NUMBER_LIMIT }) })
|
notify({ type: 'error', message: t('datasetCreation.stepOne.uploader.validation.filesNumber', { filesNumber: filesCountLimit }) })
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,10 +255,11 @@ const FileUploader = ({
|
|||||||
)
|
)
|
||||||
let files = nested.flat()
|
let files = nested.flat()
|
||||||
if (notSupportBatchUpload) files = files.slice(0, 1)
|
if (notSupportBatchUpload) files = files.slice(0, 1)
|
||||||
|
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
||||||
const valid = files.filter(isValid)
|
const valid = files.filter(isValid)
|
||||||
initialUpload(valid)
|
initialUpload(valid)
|
||||||
},
|
},
|
||||||
[initialUpload, isValid, notSupportBatchUpload, traverseFileEntry],
|
[initialUpload, isValid, notSupportBatchUpload, traverseFileEntry, fileUploadConfig],
|
||||||
)
|
)
|
||||||
const selectHandle = () => {
|
const selectHandle = () => {
|
||||||
if (fileUploader.current)
|
if (fileUploader.current)
|
||||||
@ -273,7 +274,8 @@ const FileUploader = ({
|
|||||||
onFileListUpdate?.([...fileListRef.current])
|
onFileListUpdate?.([...fileListRef.current])
|
||||||
}
|
}
|
||||||
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const files = [...(e.target.files ?? [])] as File[]
|
let files = [...(e.target.files ?? [])] as File[]
|
||||||
|
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
||||||
initialUpload(files.filter(isValid))
|
initialUpload(files.filter(isValid))
|
||||||
}, [isValid, initialUpload])
|
}, [isValid, initialUpload])
|
||||||
|
|
||||||
@ -325,6 +327,7 @@ const FileUploader = ({
|
|||||||
size: fileUploadConfig.file_size_limit,
|
size: fileUploadConfig.file_size_limit,
|
||||||
supportTypes: supportTypesShowNames,
|
supportTypes: supportTypesShowNames,
|
||||||
batchCount: fileUploadConfig.batch_count_limit,
|
batchCount: fileUploadConfig.batch_count_limit,
|
||||||
|
totalCount: fileUploadConfig.batch_upload_limit,
|
||||||
})}</div>
|
})}</div>
|
||||||
{dragging && <div ref={dragRef} className='absolute left-0 top-0 h-full w-full' />}
|
{dragging && <div ref={dragRef} className='absolute left-0 top-0 h-full w-full' />}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -38,7 +38,7 @@ const translation = {
|
|||||||
button: 'Drag and drop file or folder, or',
|
button: 'Drag and drop file or folder, or',
|
||||||
buttonSingleFile: 'Drag and drop file, or',
|
buttonSingleFile: 'Drag and drop file, or',
|
||||||
browse: 'Browse',
|
browse: 'Browse',
|
||||||
tip: 'Supports {{supportTypes}}. Max {{batchCount}} in a batch and {{size}} MB each.',
|
tip: 'Supports {{supportTypes}}. Max {{batchCount}} in a batch and {{size}} MB each. Max total {{totalCount}} files.',
|
||||||
validation: {
|
validation: {
|
||||||
typeError: 'File type not supported',
|
typeError: 'File type not supported',
|
||||||
size: 'File too large. Maximum is {{size}}MB',
|
size: 'File too large. Maximum is {{size}}MB',
|
||||||
|
|||||||
@ -38,7 +38,7 @@ const translation = {
|
|||||||
button: '拖拽文件或文件夹至此,或者',
|
button: '拖拽文件或文件夹至此,或者',
|
||||||
buttonSingleFile: '拖拽文件至此,或者',
|
buttonSingleFile: '拖拽文件至此,或者',
|
||||||
browse: '选择文件',
|
browse: '选择文件',
|
||||||
tip: '已支持 {{supportTypes}},每批最多 {{batchCount}} 个文件,每个文件不超过 {{size}} MB。',
|
tip: '已支持 {{supportTypes}},每批最多 {{batchCount}} 个文件,每个文件不超过 {{size}} MB ,总数不超过 {{totalCount}} 个文件。',
|
||||||
validation: {
|
validation: {
|
||||||
typeError: '文件类型不支持',
|
typeError: '文件类型不支持',
|
||||||
size: '文件太大了,不能超过 {{size}}MB',
|
size: '文件太大了,不能超过 {{size}}MB',
|
||||||
|
|||||||
@ -236,6 +236,7 @@ export type FileUploadConfigResponse = {
|
|||||||
audio_file_size_limit?: number // default is 50MB
|
audio_file_size_limit?: number // default is 50MB
|
||||||
video_file_size_limit?: number // default is 100MB
|
video_file_size_limit?: number // default is 100MB
|
||||||
workflow_file_upload_limit?: number // default is 10
|
workflow_file_upload_limit?: number // default is 10
|
||||||
|
batch_upload_limit: number // default is 5
|
||||||
}
|
}
|
||||||
|
|
||||||
export type InvitationResult = {
|
export type InvitationResult = {
|
||||||
|
|||||||
Reference in New Issue
Block a user