mirror of https://github.com/langgenius/dify.git
feat: Update Zod schema generation for file types and upload methods to use new constants
This commit is contained in:
parent
7c3af74b0d
commit
5b89d36ea1
|
|
@ -1,6 +1,7 @@
|
|||
import type { ZodSchema, ZodString } from 'zod'
|
||||
import { z } from 'zod'
|
||||
import { type InputFieldConfiguration, InputFieldType } from './types'
|
||||
import { SupportedFileTypes, TransferMethod } from '@/app/components/rag-pipeline/components/input-field/editor/form/schema'
|
||||
|
||||
export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
||||
const shape: Record<string, ZodSchema> = {}
|
||||
|
|
@ -28,13 +29,16 @@ export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
|||
zodType = z.string()
|
||||
break
|
||||
case InputFieldType.fileTypes:
|
||||
zodType = z.array(z.string())
|
||||
zodType = z.object({
|
||||
allowedFileExtensions: z.string().optional(),
|
||||
allowedFileTypes: z.array(SupportedFileTypes),
|
||||
})
|
||||
break
|
||||
case InputFieldType.inputTypeSelect:
|
||||
zodType = z.string()
|
||||
break
|
||||
case InputFieldType.uploadMethod:
|
||||
zodType = z.array(z.string())
|
||||
zodType = z.array(TransferMethod)
|
||||
break
|
||||
default:
|
||||
zodType = z.any()
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ export const InputType = z.enum([
|
|||
'file-list',
|
||||
])
|
||||
|
||||
const TransferMethod = z.enum([
|
||||
export const TransferMethod = z.enum([
|
||||
'all',
|
||||
'local_file',
|
||||
'remote_url',
|
||||
])
|
||||
|
||||
const SupportedFileTypes = z.enum([
|
||||
export const SupportedFileTypes = z.enum([
|
||||
'image',
|
||||
'document',
|
||||
'video',
|
||||
|
|
@ -77,19 +77,19 @@ export const createInputFieldSchema = (type: InputVarType, t: TFunction, options
|
|||
}
|
||||
if (type === InputVarType.singleFile) {
|
||||
return z.object({
|
||||
allowedFileTypes: z.array(SupportedFileTypes),
|
||||
allowedFileUploadMethods: z.array(TransferMethod),
|
||||
allowedTypesAndExtensions: z.object({
|
||||
allowedFileExtensions: z.string().optional(),
|
||||
allowedFileUploadMethods: z.array(TransferMethod),
|
||||
allowedFileExtensions: z.array(z.string()).optional(),
|
||||
allowedFileTypes: z.array(SupportedFileTypes),
|
||||
}),
|
||||
}).merge(commonSchema).passthrough()
|
||||
}
|
||||
if (type === InputVarType.multiFiles) {
|
||||
return z.object({
|
||||
allowedFileTypes: z.array(SupportedFileTypes),
|
||||
allowedFileUploadMethods: z.array(TransferMethod),
|
||||
allowedTypesAndExtensions: z.object({
|
||||
allowedFileExtensions: z.string().optional(),
|
||||
allowedFileUploadMethods: z.array(TransferMethod),
|
||||
allowedFileExtensions: z.array(z.string()).optional(),
|
||||
allowedFileTypes: z.array(SupportedFileTypes),
|
||||
}),
|
||||
maxLength: z.number().min(1).max(maxFileUploadLimit),
|
||||
}).merge(commonSchema).passthrough()
|
||||
|
|
|
|||
Loading…
Reference in New Issue