This commit is contained in:
2026-07-01 18:05:39 +08:00
parent a711a70261
commit 949066db68
2 changed files with 1 additions and 80 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ services:
CMD ["./main"]
container_name: video-factory
ports:
- "80:80"
- "80:3006"
volumes:
- /data/video-factory/workspace:/app/workspace
restart: unless-stopped
-79
View File
@@ -349,9 +349,6 @@ func (s *dramaService) generateOneSegment(ctx context.Context, d *entity.Drama,
}
}
// 保存 Agent 生成的演员/场景到数据库
s.saveGeneratedAssets(ctx, d.Id, d.Title, segOutput, characters)
// 重新加载演员列表(包含新插入的形象路径)
characters, _, _ = dao.Character.ListPageByDrama(ctx, d.Id, 1, -1)
@@ -1482,82 +1479,6 @@ func calcSegmentDurations(totalDuration, maxSingle, minSingle int) []int {
return durations
}
// saveGeneratedAssets 将 Agent 生成的演员/场景持久化到数据库
func (s *dramaService) saveGeneratedAssets(ctx context.Context, dramaId int64, dramaTitle string, segOutput *model.SegmentOutput, existingCharacters []*entity.Character) {
// ----- 演员持久化 -----
for _, ac := range segOutput.Characters {
if ac.Name == "" {
continue
}
// 按名称匹配已有演员
var matchedChar *entity.Character
for _, ec := range existingCharacters {
if ec.Name == ac.Name {
matchedChar = ec
break
}
}
if matchedChar != nil {
// 已有演员且 DB 无肖像路径 → 保存 Agent 生成的图片
if ac.ImageBase64 != "" && matchedChar.PortraitPath == "" {
if path, err := s.saveBase64Image(ctx, dramaTitle, ac.ImageBase64, "演员形象",
sanitizeDirName(matchedChar.Name)+".png"); err == nil {
matchedChar.PortraitPath = path
_ = dao.Character.Update(ctx, matchedChar.Id, matchedChar)
}
}
} else {
// 新演员 → 插入数据库
portraitPath := ""
if ac.ImageBase64 != "" {
if path, err := s.saveBase64Image(ctx, dramaTitle, ac.ImageBase64, "演员形象",
sanitizeDirName(ac.Name)+".png"); err == nil {
portraitPath = path
}
}
_, _ = dao.Character.Insert(ctx, &entity.Character{
DramaId: dramaId,
Name: ac.Name,
Description: ac.Description,
PortraitPath: portraitPath,
})
}
}
// ----- 场景持久化(仅当数据库无场景时自动创建)-----
existingScenes, err := dao.Scene.ListByDrama(ctx, dramaId)
if err == nil && len(existingScenes) == 0 && len(segOutput.Scenes) > 0 {
seen := make(map[string]bool)
for _, agentScene := range segOutput.Scenes {
if agentScene.Description == "" || seen[agentScene.Description] {
continue
}
seen[agentScene.Description] = true
// 从描述中提取场景名称(前 20 字)
sceneName := agentScene.Description
runeName := []rune(sceneName)
if len(runeName) > 20 {
sceneName = string(runeName[:20]) + "..."
}
// 保存场景图片
imagePath := ""
if agentScene.ImageBase64 != "" {
if path, err := s.saveBase64Image(ctx, dramaTitle, agentScene.ImageBase64, "场景",
sanitizeDirName(sceneName)+".png"); err == nil {
imagePath = path
}
}
_, _ = dao.Scene.Insert(ctx, &entity.Scene{
DramaId: dramaId,
Name: sceneName,
Description: agentScene.Description,
ImagePath: imagePath,
})
}
}
}
// saveBase64Image 将 base64 图片数据保存到 workspace 目录,返回绝对路径
func (s *dramaService) saveBase64Image(ctx context.Context, dramaTitle, b64Data, subDir, fileName string) (string, error) {
data, err := base64.StdEncoding.DecodeString(b64Data)
if err != nil {