fix(*): 分镜生成设置 - 统一模型能力计价并支持项目默认模型
This commit is contained in:
@@ -14,25 +14,29 @@ import (
|
||||
)
|
||||
|
||||
type CreateProjectRequest struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
AspectRatio string `json:"aspectRatio"`
|
||||
SourceType string `json:"sourceType"`
|
||||
Description string `json:"description"`
|
||||
StylePresetID string `json:"stylePresetId"`
|
||||
StyleProfileJSON string `json:"styleProfileJson"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
AspectRatio string `json:"aspectRatio"`
|
||||
SourceType string `json:"sourceType"`
|
||||
Description string `json:"description"`
|
||||
StylePresetID string `json:"stylePresetId"`
|
||||
StyleProfileJSON string `json:"styleProfileJson"`
|
||||
DefaultImageModel string `json:"defaultImageModel"`
|
||||
DefaultVideoModel string `json:"defaultVideoModel"`
|
||||
}
|
||||
|
||||
type UpdateProjectRequest struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
AspectRatio string `json:"aspectRatio"`
|
||||
SourceType string `json:"sourceType"`
|
||||
Description *string `json:"description"`
|
||||
CoverResourceID *string `json:"coverResourceId"`
|
||||
StylePresetID *string `json:"stylePresetId"`
|
||||
StyleProfileJSON *string `json:"styleProfileJson"`
|
||||
Status string `json:"status"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
AspectRatio string `json:"aspectRatio"`
|
||||
SourceType string `json:"sourceType"`
|
||||
Description *string `json:"description"`
|
||||
CoverResourceID *string `json:"coverResourceId"`
|
||||
StylePresetID *string `json:"stylePresetId"`
|
||||
StyleProfileJSON *string `json:"styleProfileJson"`
|
||||
DefaultImageModel *string `json:"defaultImageModel"`
|
||||
DefaultVideoModel *string `json:"defaultVideoModel"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type CreateProjectUnitRequest struct {
|
||||
@@ -240,7 +244,15 @@ func (s *Service) CreateProject(userID string, req CreateProjectRequest) (model.
|
||||
return model.Project{}, BadAuthRequest(err.Error())
|
||||
}
|
||||
now := time.Now()
|
||||
project := model.Project{ID: newID(), UserID: userID, Name: name, Type: projectType, AspectRatio: aspectRatio, SourceType: sourceType, Description: strings.TrimSpace(req.Description), StylePresetID: stylePresetID, StyleProfileJSON: styleProfileJSON, Status: model.ProjectStatusActive, Revision: 1, CreatedAt: now, UpdatedAt: now}
|
||||
defaultImageModel, err := normalizeProjectDefaultModel(req.DefaultImageModel)
|
||||
if err != nil {
|
||||
return model.Project{}, err
|
||||
}
|
||||
defaultVideoModel, err := normalizeProjectDefaultModel(req.DefaultVideoModel)
|
||||
if err != nil {
|
||||
return model.Project{}, err
|
||||
}
|
||||
project := model.Project{ID: newID(), UserID: userID, Name: name, Type: projectType, AspectRatio: aspectRatio, SourceType: sourceType, Description: strings.TrimSpace(req.Description), StylePresetID: stylePresetID, StyleProfileJSON: styleProfileJSON, DefaultImageModel: defaultImageModel, DefaultVideoModel: defaultVideoModel, Status: model.ProjectStatusActive, Revision: 1, CreatedAt: now, UpdatedAt: now}
|
||||
if err := s.repo.CreateProject(&project); err != nil {
|
||||
return model.Project{}, err
|
||||
}
|
||||
@@ -301,6 +313,20 @@ func (s *Service) UpdateProject(userID string, id string, req UpdateProjectReque
|
||||
}
|
||||
project.StyleProfileJSON = styleProfileJSON
|
||||
}
|
||||
if req.DefaultImageModel != nil {
|
||||
defaultImageModel, modelErr := normalizeProjectDefaultModel(*req.DefaultImageModel)
|
||||
if modelErr != nil {
|
||||
return model.Project{}, modelErr
|
||||
}
|
||||
project.DefaultImageModel = defaultImageModel
|
||||
}
|
||||
if req.DefaultVideoModel != nil {
|
||||
defaultVideoModel, modelErr := normalizeProjectDefaultModel(*req.DefaultVideoModel)
|
||||
if modelErr != nil {
|
||||
return model.Project{}, modelErr
|
||||
}
|
||||
project.DefaultVideoModel = defaultVideoModel
|
||||
}
|
||||
if err := validateStyleProfilePreset(project.StylePresetID, project.StyleProfileJSON); err != nil {
|
||||
return model.Project{}, BadAuthRequest(err.Error())
|
||||
}
|
||||
@@ -318,6 +344,14 @@ func (s *Service) UpdateProject(userID string, id string, req UpdateProjectReque
|
||||
return *project, nil
|
||||
}
|
||||
|
||||
func normalizeProjectDefaultModel(value string) (string, error) {
|
||||
modelRef := strings.TrimSpace(value)
|
||||
if len(modelRef) > 500 {
|
||||
return "", BadAuthRequest("项目默认模型标识过长")
|
||||
}
|
||||
return modelRef, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteProject(userID string, id string) error {
|
||||
if _, err := s.repo.ProjectForUser(userID, id); err != nil {
|
||||
return err
|
||||
|
||||
@@ -82,6 +82,42 @@ func TestUpdateProjectCoverRequiresOwnedReadyImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateProjectPersistsDefaultGenerationModels(t *testing.T) {
|
||||
service, db := newProjectSettingsTestService(t)
|
||||
now := time.Now()
|
||||
project := model.Project{ID: "project-model-defaults", UserID: "user-1", Name: "短剧", Status: model.ProjectStatusActive, Revision: 1, CreatedAt: now, UpdatedAt: now}
|
||||
if err := db.Create(&project).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
imageModel := " system-channel::image-model "
|
||||
videoModel := "user-channel::MiniMax-H3"
|
||||
updated, err := service.UpdateProject("user-1", project.ID, UpdateProjectRequest{DefaultImageModel: &imageModel, DefaultVideoModel: &videoModel})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if updated.DefaultImageModel != "system-channel::image-model" || updated.DefaultVideoModel != videoModel {
|
||||
t.Fatalf("updated model defaults = %q / %q", updated.DefaultImageModel, updated.DefaultVideoModel)
|
||||
}
|
||||
|
||||
var persisted model.Project
|
||||
if err := db.First(&persisted, "id = ?", project.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if persisted.DefaultImageModel != updated.DefaultImageModel || persisted.DefaultVideoModel != updated.DefaultVideoModel {
|
||||
t.Fatalf("persisted model defaults = %q / %q", persisted.DefaultImageModel, persisted.DefaultVideoModel)
|
||||
}
|
||||
|
||||
empty := ""
|
||||
cleared, err := service.UpdateProject("user-1", project.ID, UpdateProjectRequest{DefaultVideoModel: &empty})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cleared.DefaultVideoModel != "" {
|
||||
t.Fatalf("default video model = %q after clear", cleared.DefaultVideoModel)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectUnitSummaryPersistsWordCount(t *testing.T) {
|
||||
service, db := newProjectSettingsTestService(t)
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user