From 949066db6826e22fa234a8564f48077678f2b5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=96=8C?= <259278618@qq.com> Date: Wed, 1 Jul 2026 18:05:39 +0800 Subject: [PATCH] 1 --- docker-compose.yml | 2 +- shortdrama/service/drama_service.go | 79 ----------------------------- 2 files changed, 1 insertion(+), 80 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a946553..17f271d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/shortdrama/service/drama_service.go b/shortdrama/service/drama_service.go index d447dae..f0263c5 100644 --- a/shortdrama/service/drama_service.go +++ b/shortdrama/service/drama_service.go @@ -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 {