mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 02:06:35 +08:00
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 type { ZodSchema, ZodString } from 'zod'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { type InputFieldConfiguration, InputFieldType } from './types'
|
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>[]) => {
|
export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
||||||
const shape: Record<string, ZodSchema> = {}
|
const shape: Record<string, ZodSchema> = {}
|
||||||
@ -28,13 +29,16 @@ export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
|||||||
zodType = z.string()
|
zodType = z.string()
|
||||||
break
|
break
|
||||||
case InputFieldType.fileTypes:
|
case InputFieldType.fileTypes:
|
||||||
zodType = z.array(z.string())
|
zodType = z.object({
|
||||||
|
allowedFileExtensions: z.string().optional(),
|
||||||
|
allowedFileTypes: z.array(SupportedFileTypes),
|
||||||
|
})
|
||||||
break
|
break
|
||||||
case InputFieldType.inputTypeSelect:
|
case InputFieldType.inputTypeSelect:
|
||||||
zodType = z.string()
|
zodType = z.string()
|
||||||
break
|
break
|
||||||
case InputFieldType.uploadMethod:
|
case InputFieldType.uploadMethod:
|
||||||
zodType = z.array(z.string())
|
zodType = z.array(TransferMethod)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
zodType = z.any()
|
zodType = z.any()
|
||||||
|
|||||||
@ -16,13 +16,13 @@ export const InputType = z.enum([
|
|||||||
'file-list',
|
'file-list',
|
||||||
])
|
])
|
||||||
|
|
||||||
const TransferMethod = z.enum([
|
export const TransferMethod = z.enum([
|
||||||
'all',
|
'all',
|
||||||
'local_file',
|
'local_file',
|
||||||
'remote_url',
|
'remote_url',
|
||||||
])
|
])
|
||||||
|
|
||||||
const SupportedFileTypes = z.enum([
|
export const SupportedFileTypes = z.enum([
|
||||||
'image',
|
'image',
|
||||||
'document',
|
'document',
|
||||||
'video',
|
'video',
|
||||||
@ -77,19 +77,19 @@ export const createInputFieldSchema = (type: InputVarType, t: TFunction, options
|
|||||||
}
|
}
|
||||||
if (type === InputVarType.singleFile) {
|
if (type === InputVarType.singleFile) {
|
||||||
return z.object({
|
return z.object({
|
||||||
allowedFileTypes: z.array(SupportedFileTypes),
|
allowedFileUploadMethods: z.array(TransferMethod),
|
||||||
allowedTypesAndExtensions: z.object({
|
allowedTypesAndExtensions: z.object({
|
||||||
allowedFileExtensions: z.string().optional(),
|
allowedFileExtensions: z.array(z.string()).optional(),
|
||||||
allowedFileUploadMethods: z.array(TransferMethod),
|
allowedFileTypes: z.array(SupportedFileTypes),
|
||||||
}),
|
}),
|
||||||
}).merge(commonSchema).passthrough()
|
}).merge(commonSchema).passthrough()
|
||||||
}
|
}
|
||||||
if (type === InputVarType.multiFiles) {
|
if (type === InputVarType.multiFiles) {
|
||||||
return z.object({
|
return z.object({
|
||||||
allowedFileTypes: z.array(SupportedFileTypes),
|
allowedFileUploadMethods: z.array(TransferMethod),
|
||||||
allowedTypesAndExtensions: z.object({
|
allowedTypesAndExtensions: z.object({
|
||||||
allowedFileExtensions: z.string().optional(),
|
allowedFileExtensions: z.array(z.string()).optional(),
|
||||||
allowedFileUploadMethods: z.array(TransferMethod),
|
allowedFileTypes: z.array(SupportedFileTypes),
|
||||||
}),
|
}),
|
||||||
maxLength: z.number().min(1).max(maxFileUploadLimit),
|
maxLength: z.number().min(1).max(maxFileUploadLimit),
|
||||||
}).merge(commonSchema).passthrough()
|
}).merge(commonSchema).passthrough()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user