/* * @Author: ZhaoYing * @Date: 2026-03-05 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-03-19 15:18:20 */ import { forwardRef, useImperativeHandle, useState } from 'react'; import { Form, InputNumber, Flex, Switch, Row, Col, Radio } from 'antd'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx'; import RbModal from '@/components/RbModal'; import type { FeaturesConfigForm } from '../../types' type FileUpload = Omit interface FileUploadSettingModalRef { handleOpen: (values?: FileUpload) => void; handleClose: () => void; } interface FileUploadSettingModalProps { onSave: (values: FileUpload) => void; } const fileTypeOptions = [ { type: 'document', icon:
, formats: [ "pdf", "docx", "doc", "xlsx", "xls", "txt", "csv", "json", "md", ], }, { type: 'image', icon:
, formats: [ "png", "jpg", "jpeg" ], }, { type: 'audio', icon:
, formats: [ "mp3", "wav", "m4a", ], }, { type: 'video', icon:
, formats: [ "mp4", "mov", ], }, ]; const defaultValues: FileUpload = { enabled: false, image_enabled: false, image_max_size_mb: 20, image_allowed_extensions: [ "png", "jpg", "jpeg" ], audio_enabled: false, audio_max_size_mb: 50, audio_allowed_extensions: [ "mp3", "wav", "m4a", "ogg", "flac" ], document_enabled: false, document_max_size_mb: 100, document_allowed_extensions: [ "pdf", "docx", "xlsx", "txt", "csv", "json" ], video_enabled: false, video_max_size_mb: 100, video_allowed_extensions: [ "mp4", "mov", "avi", "webm" ], max_file_count: 5, allowed_transfer_methods: 'both' } const FileUploadSettingModal = forwardRef(({ onSave, }, ref) => { const { t } = useTranslation(); const [visible, setVisible] = useState(false); const [form] = Form.useForm(); const values = Form.useWatch([], form) const handleClose = () => { setVisible(false); form.resetFields(); }; const handleOpen = (values?: FileUpload) => { setVisible(true); if (values) { const methods = values.allowed_transfer_methods || ['local_file', 'remote_url'] const transferMethod = Array.isArray(methods) ? methods.length === 2 ? 'both' : methods[0] : methods form.setFieldsValue({ ...values, allowed_transfer_methods: transferMethod as any }) } else { form.setFieldsValue(defaultValues) } }; const handleSave = async () => { const vals = await form.validateFields(); const methodMap: Record = { local_file: ['local_file'], remote_url: ['remote_url'], both: ['local_file', 'remote_url'], } onSave({ ...vals, allowed_transfer_methods: methodMap[vals.allowed_transfer_methods as unknown as string] ?? [] }); handleClose(); }; useImperativeHandle(ref, () => ({ handleOpen, handleClose })); return (
{t('application.local')} URL {t('application.both')}
{t('application.maxCount')}
{fileTypeOptions.map((option) => { const enabledKey = `${option.type}_enabled` as keyof FileUpload const sizeKey = `${option.type}_max_size_mb` as keyof FileUpload const isEnabled = values?.[enabledKey] return (
{option.icon}
{t(`application.${option.type}`)}
{option.formats.map(item => item.toUpperCase()).join(', ')}
{isEnabled && (
{t('application.singleMaxSize')}:
)}
) })}
); }); export default FileUploadSettingModal;