feat(*): 创作配置 - 支持 Midjourney、多图保存与自定义公告
Co-authored-by: ddcat666 <26564566+ddcat666@users.noreply.github.com>
This commit is contained in:
93
backend/internal/app/model_capability_screen_spec.go
Normal file
93
backend/internal/app/model_capability_screen_spec.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AutoDL's complete resolution enum also controls orientation. The bundled
|
||||
// workflow contract supplies fixed choices; client-supplied fixed values are ignored.
|
||||
func normalizeAutoDLVideoScreenSpec(profile *VideoCapabilityConfig, modelName string) (*VideoCapabilityConfig, error) {
|
||||
dir, err := officialPluginPackageDir()
|
||||
if err != nil {
|
||||
return nil, BadAuthRequest("无法读取 AutoDL 工作流规格")
|
||||
}
|
||||
pkg, err := inspectOfficialPluginPackage(filepath.Join(dir, "autodl-comfyui.yingce-plugin"))
|
||||
if err != nil {
|
||||
return nil, BadAuthRequest("无法读取 AutoDL 工作流规格")
|
||||
}
|
||||
modelName = strings.TrimPrefix(strings.TrimSpace(modelName), "models/")
|
||||
fixed := VideoScreenSpecConfig{Ratios: []string{}, Resolutions: []string{}}
|
||||
found := false
|
||||
for _, workflow := range pkg.info.Manifest.Contributes.Workflows {
|
||||
if workflow.ID != modelName || workflow.ProviderID != "autodl-comfyui" {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
for _, parameter := range workflow.Parameters {
|
||||
if parameter.Mapping != "resolution" && parameter.Name != "resolution" {
|
||||
continue
|
||||
}
|
||||
fixed.Resolutions = cleanVideoScreenSpecValues(parameter.Values)
|
||||
fixed.DefaultResolution, _ = workflow.Defaults[parameter.Name].(string)
|
||||
fixed.DefaultResolution = strings.TrimSpace(fixed.DefaultResolution)
|
||||
}
|
||||
break
|
||||
}
|
||||
if !found || len(fixed.Resolutions) == 0 || !containsCapabilityString(fixed.Resolutions, fixed.DefaultResolution) {
|
||||
return nil, BadAuthRequest("当前 AutoDL 工作流未声明有效的分辨率列表和默认值")
|
||||
}
|
||||
value := *profile
|
||||
// No AutoDL v2.3 workflow declares an independent aspect-ratio parameter.
|
||||
value.Ratios, value.DefaultRatio = []string{}, ""
|
||||
value.Resolutions = cleanVideoScreenSpecValues(profile.Resolutions)
|
||||
value.DefaultResolution = strings.TrimSpace(profile.DefaultResolution)
|
||||
for i, resolution := range value.Resolutions {
|
||||
matched := false
|
||||
for _, preset := range fixed.Resolutions {
|
||||
if strings.EqualFold(resolution, preset) {
|
||||
value.Resolutions[i] = preset
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
return nil, BadAuthRequest("分辨率不在当前 AutoDL 工作流的插件预设中:" + resolution)
|
||||
}
|
||||
if strings.EqualFold(value.Resolutions[i], value.DefaultResolution) {
|
||||
value.DefaultResolution = value.Resolutions[i]
|
||||
}
|
||||
}
|
||||
if len(value.Resolutions) == 0 || !containsCapabilityString(value.Resolutions, value.DefaultResolution) {
|
||||
return nil, BadAuthRequest("请至少选择一个完整分辨率,并从所选值中设置默认值")
|
||||
}
|
||||
value.FixedScreenSpec = &fixed
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func cleanVideoScreenSpecValues(values []string) []string {
|
||||
result := make([]string, 0, len(values))
|
||||
seen := make(map[string]bool)
|
||||
for _, value := range values {
|
||||
value = strings.TrimSpace(value)
|
||||
key := strings.ToLower(value)
|
||||
if value != "" && !seen[key] {
|
||||
result = append(result, value)
|
||||
seen[key] = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func applyAutoDLVideoScreenSpec(input *canvasGenerationInput, profile *VideoCapabilityConfig) {
|
||||
if input == nil || profile == nil || profile.FixedScreenSpec == nil {
|
||||
return
|
||||
}
|
||||
input.Config.Size = ""
|
||||
resolution := videoResolutionNameRequest(profile, input.Config.VQuality)
|
||||
if resolution != "" {
|
||||
input.Config.VQuality = resolution
|
||||
} else if isAutomaticVideoResolution(input.Config.VQuality) {
|
||||
input.Config.VQuality = profile.DefaultResolution
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user