Files
video-factory/shortdrama/controller/config_controller.go
T
2026-07-03 13:58:30 +08:00

94 lines
3.3 KiB
Go

package controller
import (
"context"
"fmt"
"video-factory/shortdrama/model/dto"
"video-factory/shortdrama/model/entity"
"video-factory/shortdrama/service"
)
type config struct{}
var Config = new(config)
func (c *config) Get(ctx context.Context, req *dto.GetModelConfigReq) (res *dto.GetModelConfigRes, err error) {
cfg := service.ConfigService.Get(ctx)
return &dto.GetModelConfigRes{ModelConfig: cfg}, nil
}
func (c *config) Save(ctx context.Context, req *dto.SaveModelConfigReq) (res *struct{}, err error) {
if req.MinSingleDuration < 1 {
return nil, fmt.Errorf("单次生成最小时长必须大于等于1")
}
if req.MaxSingleDuration < 1 {
return nil, fmt.Errorf("单次生成最大时长必须大于等于1")
}
if req.MinSingleDuration > req.MaxSingleDuration {
return nil, fmt.Errorf("单次生成最小时长不能大于最大时长")
}
if req.VideoModelCategory == "i2v" {
if req.MaxRefVideoCount < 1 {
return nil, fmt.Errorf("图生图模式下,参考视频数量必须大于0")
}
if req.MaxRefVideoFileSize < 1 {
return nil, fmt.Errorf("图生图模式下,单个参考视频最大大小必须填写")
}
if req.MaxRefVideoDuration < 1 {
return nil, fmt.Errorf("图生图模式下,单个参考视频最大时长必须填写")
}
if req.RefVideoFormats == "" {
return nil, fmt.Errorf("图生图模式下,允许的视频格式不能为空")
}
if req.MaxRefAudioCount < 1 {
return nil, fmt.Errorf("图生图模式下,参考音频数量必须大于0")
}
if req.MaxRefAudioFileSize < 1 {
return nil, fmt.Errorf("图生图模式下,单个参考音频最大大小必须填写")
}
if req.MaxRefAudioDuration < 1 {
return nil, fmt.Errorf("图生图模式下,单个参考音频最大时长必须填写")
}
if req.RefAudioFormats == "" {
return nil, fmt.Errorf("图生图模式下,允许的音频格式不能为空")
}
if req.MaxReferenceImages < 2 {
return nil, fmt.Errorf("图生图模式下,单次生成最大参考图数量至少为2")
}
if req.MaxRefImageFileSize < 1 {
return nil, fmt.Errorf("图生图模式下,单个参考图片最大大小必须填写")
}
if req.RefImageFormats == "" {
return nil, fmt.Errorf("图生图模式下,允许的图片格式不能为空")
}
}
cfg := &entity.ModelConfig{
ChatApiKey: req.ChatApiKey,
ChatBaseUrl: req.ChatBaseUrl,
ChatModelName: req.ChatModelName,
MaxTokens: req.MaxTokens,
Temperature: req.Temperature,
VideoApiKey: req.VideoApiKey,
VideoBaseUrl: req.VideoBaseUrl,
VideoModelName: req.VideoModelName,
VideoQueryUrl: req.VideoQueryUrl,
MinSingleDuration: req.MinSingleDuration,
MaxSingleDuration: req.MaxSingleDuration,
VideoModelCategory: req.VideoModelCategory,
MaxReferenceImages: req.MaxReferenceImages,
MaxRefVideoCount: req.MaxRefVideoCount,
MaxRefVideoFileSize: req.MaxRefVideoFileSize,
MaxRefVideoDuration: req.MaxRefVideoDuration,
RefVideoFormats: req.RefVideoFormats,
MaxRefAudioCount: req.MaxRefAudioCount,
MaxRefAudioFileSize: req.MaxRefAudioFileSize,
MaxRefAudioDuration: req.MaxRefAudioDuration,
RefAudioFormats: req.RefAudioFormats,
MaxRefImageFileSize: req.MaxRefImageFileSize,
RefImageFormats: req.RefImageFormats,
}
return nil, service.ConfigService.Save(ctx, cfg)
}