返回 AiToEarn
useDraftReferenceMaxImages.ts
根目录 / project / aitoearn-web / src / components / draft-box / hooks / useDraftReferenceMaxImages.ts
1 'use client'
2
3 import { useMemo } from 'react'
4 import { usePricingData } from '@/components/draft-box/components/AiBatchGenerateBar/hooks/usePricingData'
5 import { DEFAULT_MAX_INPUT_IMAGES, getVideoModelStaticConfig } from '@/components/draft-box/components/AiBatchGenerateBar/utils/constants'
6 import { useDraftBoxConfigStore } from '@/store/draft-box/draftBoxConfigStore'
7
8 /**
9 * useDraftReferenceMaxImages - 读取当前草稿箱 AI 参考文件图片上限
10 * 复用 AI 批量生成栏的当前内容类型与模型配置,避免不同入口各自维护限制
11 */
12 export function useDraftReferenceMaxImages(groupId: string) {
13 const { pricingData } = usePricingData()
14 const configSnapshot = useDraftBoxConfigStore(state => state.configs[groupId])
15 const getConfig = useDraftBoxConfigStore(state => state.getConfig)
16
17 const config = configSnapshot ?? getConfig(groupId)
18
19 return useMemo(() => {
20 if (config.contentType === 'image_text') {
21 const currentImageModelInfo = pricingData?.imageModels?.find(model => model.model === config.imageModel)
22 return currentImageModelInfo?.maxInputImages ?? DEFAULT_MAX_INPUT_IMAGES
23 }
24
25 const fallbackVideoModelType = config.modelType || pricingData?.videoModels?.[0]?.name || ''
26 return getVideoModelStaticConfig(fallbackVideoModelType, pricingData?.videoModels).maxImages
27 }, [config.contentType, config.imageModel, config.modelType, pricingData])
28 }
29
29 lines TYPESCRIPT