fix: 前端加载时规范化历史模型尺寸
This commit is contained in:
1 parent
0b521d88c9
commit
9cd01eeec4
1 file changed
+28
-2
@@ -75,6 +75,22 @@ function defaultOptions(item: GenerationModelItem): GenerationOptions {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 把历史 Profile 中已不属于当前模型 Schema 的参数收敛为当前模型默认值。 */
|
||||||
|
function normalizeSavedOptions(item: GenerationModelItem | undefined, saved: GenerationOptions): GenerationOptions {
|
||||||
|
if (!item) return { ...saved }
|
||||||
|
const defaults = defaultOptions(item)
|
||||||
|
const normalized = { ...saved }
|
||||||
|
for (const schema of item.generationOptions) {
|
||||||
|
const value = normalized[schema.key]
|
||||||
|
if (schema.type !== 'size' || typeof value !== 'string' || !schema.options?.length) continue
|
||||||
|
if (schema.options.some(option => option.value === value)) continue
|
||||||
|
const fallback = defaults[schema.key]
|
||||||
|
if (fallback !== undefined) normalized[schema.key] = fallback
|
||||||
|
else delete normalized[schema.key]
|
||||||
|
}
|
||||||
|
return normalized
|
||||||
|
}
|
||||||
|
|
||||||
function selectModel(type: 'image' | 'video', value: string) {
|
function selectModel(type: 'image' | 'video', value: string) {
|
||||||
if (!profile.value) return
|
if (!profile.value) return
|
||||||
const items = type === 'image' ? enabledImages.value : enabledVideos.value
|
const items = type === 'image' ? enabledImages.value : enabledVideos.value
|
||||||
@@ -122,15 +138,25 @@ async function load() {
|
|||||||
generationConfigApi.profile(props.projectId, controller.signal)
|
generationConfigApi.profile(props.projectId, controller.signal)
|
||||||
])
|
])
|
||||||
catalog.value = nextCatalog
|
catalog.value = nextCatalog
|
||||||
|
const savedImageModel = saved
|
||||||
|
? nextCatalog.images.find(
|
||||||
|
item => item.provider === saved.imageProvider && item.model === saved.imageModel
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
const savedVideoModel = saved
|
||||||
|
? nextCatalog.videos.find(
|
||||||
|
item => item.provider === saved.videoProvider && item.model === saved.videoModel
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
profile.value = saved
|
profile.value = saved
|
||||||
? {
|
? {
|
||||||
aspectRatio: saved.aspectRatio,
|
aspectRatio: saved.aspectRatio,
|
||||||
imageProvider: saved.imageProvider,
|
imageProvider: saved.imageProvider,
|
||||||
imageModel: saved.imageModel,
|
imageModel: saved.imageModel,
|
||||||
imageOptions: { ...saved.imageOptions },
|
imageOptions: normalizeSavedOptions(savedImageModel, saved.imageOptions),
|
||||||
videoProvider: saved.videoProvider,
|
videoProvider: saved.videoProvider,
|
||||||
videoModel: saved.videoModel,
|
videoModel: saved.videoModel,
|
||||||
videoOptions: { ...saved.videoOptions }
|
videoOptions: normalizeSavedOptions(savedVideoModel, saved.videoOptions)
|
||||||
}
|
}
|
||||||
: createInitial(nextCatalog)
|
: createInitial(nextCatalog)
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
|
|||||||
Reference in new issue
Block a user