feat(short-drama-agent-front): 接入图片持续授权与视频费用审计
This commit is contained in:
1 parent
3915566994
commit
1e9ef33d1d
39 files changed
+3442
-51
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import { ref, watch, type Ref } from 'vue'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { generationConfigApi } from './api'
|
||||
import type { CreativeProfile, GenerationModelCatalog, GenerationOptions } from './types'
|
||||
|
||||
/**
|
||||
@@ -15,7 +18,10 @@ export function imageGenerationDefaults(
|
||||
} {
|
||||
const selected =
|
||||
catalog.images.find(item => item.provider === profile.imageProvider && item.enabled) ??
|
||||
catalog.images.find(item => item.enabled)
|
||||
(!profile.imageProvider
|
||||
? (catalog.images.find(item => item.provider === catalog.defaults.imageProvider && item.enabled) ??
|
||||
catalog.images.find(item => item.isDefault && item.enabled))
|
||||
: undefined)
|
||||
const options: GenerationOptions = {
|
||||
...selected?.defaults,
|
||||
...(selected?.provider === profile.imageProvider ? profile.imageOptions : {})
|
||||
@@ -25,3 +31,59 @@ export function imageGenerationDefaults(
|
||||
options.size = selected?.defaults.size ?? size.options[0]?.value ?? ''
|
||||
return { provider: selected?.provider ?? '', options }
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开原图片表单时读取项目与主体覆盖配置,迟到结果不覆盖用户选择。
|
||||
* @param open 当前生成表单开关
|
||||
* @param profile 原项目配置
|
||||
* @param targetId 正式主体编号,形态沿所属主体的覆盖配置
|
||||
* @param selectionKey 表单目标变化时重新读取默认配置
|
||||
* @returns 可编辑模型、参数及读取状态
|
||||
*/
|
||||
export function useAssetImageDefaults(
|
||||
open: Ref<boolean>,
|
||||
profile: () => CreativeProfile,
|
||||
targetId: () => string,
|
||||
selectionKey: () => string = targetId
|
||||
) {
|
||||
/** 本次显式供应方,解析完成前不提供生成资格。 */
|
||||
const provider = ref('')
|
||||
/** 服务端按项目及主体覆盖解析的参数。 */
|
||||
const generationOptions = ref<GenerationOptions>({})
|
||||
/** 原配置只读加载。 */
|
||||
const configLoading = ref(false)
|
||||
/** 配置读取失败,不回退其它供应方。 */
|
||||
const configError = ref('')
|
||||
watch(
|
||||
[open, () => profile().projectId, targetId, selectionKey],
|
||||
async ([shown], _, onCleanup) => {
|
||||
provider.value = ''
|
||||
generationOptions.value = {}
|
||||
configError.value = ''
|
||||
configLoading.value = false
|
||||
if (!shown || !targetId()) return
|
||||
const controller = new AbortController()
|
||||
onCleanup(() => controller.abort())
|
||||
configLoading.value = true
|
||||
try {
|
||||
const resolved = await generationConfigApi.resolve(
|
||||
profile().projectId,
|
||||
'image',
|
||||
{ target: { targetType: 'asset', targetId: targetId() } },
|
||||
controller.signal
|
||||
)
|
||||
if (controller.signal.aborted) return
|
||||
if (!resolved.provider || !resolved.model || !resolved.options)
|
||||
throw new Error('当前主体模型配置不完整,请重新读取。')
|
||||
provider.value = resolved.provider
|
||||
generationOptions.value = { ...resolved.options }
|
||||
} catch (cause) {
|
||||
if (!controller.signal.aborted) configError.value = errorMessage(cause)
|
||||
} finally {
|
||||
if (!controller.signal.aborted) configLoading.value = false
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
return { provider, generationOptions, configLoading, configError }
|
||||
}
|
||||
Reference in new issue
Block a user