|
@@ -12,34 +12,46 @@ import ConfigContext from '@/context/debug-configuration'
|
|
// import { Resolution } from '@/types/app'
|
|
// import { Resolution } from '@/types/app'
|
|
import { useFeatures, useFeaturesStore } from '@/app/components/base/features/hooks'
|
|
import { useFeatures, useFeaturesStore } from '@/app/components/base/features/hooks'
|
|
import Switch from '@/app/components/base/switch'
|
|
import Switch from '@/app/components/base/switch'
|
|
-import type { FileUpload } from '@/app/components/base/features/types'
|
|
|
|
|
|
+import { SupportUploadFileTypes } from '@/app/components/workflow/types'
|
|
|
|
|
|
const ConfigVision: FC = () => {
|
|
const ConfigVision: FC = () => {
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
- const { isShowVisionConfig } = useContext(ConfigContext)
|
|
|
|
|
|
+ const { isShowVisionConfig, isAllowVideoUpload } = useContext(ConfigContext)
|
|
const file = useFeatures(s => s.features.file)
|
|
const file = useFeatures(s => s.features.file)
|
|
const featuresStore = useFeaturesStore()
|
|
const featuresStore = useFeaturesStore()
|
|
|
|
|
|
- const handleChange = useCallback((data: FileUpload) => {
|
|
|
|
|
|
+ const isImageEnabled = file?.allowed_file_types?.includes(SupportUploadFileTypes.image) ?? false
|
|
|
|
+
|
|
|
|
+ const handleChange = useCallback((value: boolean) => {
|
|
const {
|
|
const {
|
|
features,
|
|
features,
|
|
setFeatures,
|
|
setFeatures,
|
|
} = featuresStore!.getState()
|
|
} = featuresStore!.getState()
|
|
|
|
|
|
const newFeatures = produce(features, (draft) => {
|
|
const newFeatures = produce(features, (draft) => {
|
|
- draft.file = {
|
|
|
|
- ...draft.file,
|
|
|
|
- enabled: data.enabled,
|
|
|
|
- image: {
|
|
|
|
- enabled: data.enabled,
|
|
|
|
- detail: data.image?.detail,
|
|
|
|
- transfer_methods: data.image?.transfer_methods,
|
|
|
|
- number_limits: data.image?.number_limits,
|
|
|
|
- },
|
|
|
|
|
|
+ if (value) {
|
|
|
|
+ draft.file!.allowed_file_types = Array.from(new Set([
|
|
|
|
+ ...(draft.file?.allowed_file_types || []),
|
|
|
|
+ SupportUploadFileTypes.image,
|
|
|
|
+ ...(isAllowVideoUpload ? [SupportUploadFileTypes.video] : []),
|
|
|
|
+ ]))
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ draft.file!.allowed_file_types = draft.file!.allowed_file_types?.filter(
|
|
|
|
+ type => type !== SupportUploadFileTypes.image && (isAllowVideoUpload ? type !== SupportUploadFileTypes.video : true),
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (draft.file) {
|
|
|
|
+ draft.file.enabled = (draft.file.allowed_file_types?.length ?? 0) > 0
|
|
|
|
+ draft.file.image = {
|
|
|
|
+ ...(draft.file.image || {}),
|
|
|
|
+ enabled: value,
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
setFeatures(newFeatures)
|
|
setFeatures(newFeatures)
|
|
- }, [featuresStore])
|
|
|
|
|
|
+ }, [featuresStore, isAllowVideoUpload])
|
|
|
|
|
|
if (!isShowVisionConfig)
|
|
if (!isShowVisionConfig)
|
|
return null
|
|
return null
|
|
@@ -89,11 +101,8 @@ const ConfigVision: FC = () => {
|
|
<ParamConfig />
|
|
<ParamConfig />
|
|
<div className='ml-1 mr-3 w-[1px] h-3.5 bg-divider-subtle'></div>
|
|
<div className='ml-1 mr-3 w-[1px] h-3.5 bg-divider-subtle'></div>
|
|
<Switch
|
|
<Switch
|
|
- defaultValue={file?.enabled}
|
|
|
|
- onChange={value => handleChange({
|
|
|
|
- ...(file || {}),
|
|
|
|
- enabled: value,
|
|
|
|
- })}
|
|
|
|
|
|
+ defaultValue={isImageEnabled}
|
|
|
|
+ onChange={handleChange}
|
|
size='md'
|
|
size='md'
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|