fix(projects): 短剧项目 - 修复同名创建重试 (#691)

Co-authored-by: tanzui <305375675@.com>
This commit is contained in:
tanzui
2026-10-06 09:24:11 +08:00
committed by GitHub
parent 544daa4b9f
commit 53ee5b0cbd
14 changed files with 350 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"time"
@@ -254,6 +255,12 @@ func (s *Service) CreateProject(userID string, req CreateProjectRequest) (model.
}
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 {
if errors.Is(err, repository.ErrProjectNameConflict) {
// 项目名称冲突需要明确返回 409,页面才能按已有逻辑换一个名称重试。
conflict := NewAppError(http.StatusConflict, "项目名称已存在")
conflict.Reason = ReasonProjectNameConflict
return model.Project{}, conflict
}
return model.Project{}, err
}
if _, err := s.createProjectWorkflow(project.ID, "", "project"); err != nil {