Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix: repair subtitle file downloads
沈浩4cc9caa28580
diff --git a/internal/handler/subtitle_task.go b/internal/handler/subtitle_task.goindex 52c24372..26a22d27 100644--- a/internal/handler/subtitle_task.go+++ b/internal/handler/subtitle_task.go@@ -4,6 +4,8 @@ import ("github.com/gin-gonic/gin""krillin-ai/internal/dto""krillin-ai/internal/response"+ "os"+ "path/filepath")func (h Handler) StartSubtitleTask(c *gin.Context) {@@ -89,3 +91,26 @@ func (h Handler) UploadFile(c *gin.Context) {Data: gin.H{"file_path": "local:" + savePath},})}++func (h Handler) DownloadFile(c *gin.Context) {+ requestedFile := c.Param("filepath")+ if requestedFile == "" {+ response.R(c, response.Response{+ Error: -1,+ Msg: "文件路径为空",+ Data: nil,+ })+ return+ }++ localFilePath := filepath.Join(".", requestedFile)+ if _, err := os.Stat(localFilePath); os.IsNotExist(err) {+ response.R(c, response.Response{+ Error: -1,+ Msg: "文件不存在",+ Data: nil,+ })+ return+ }+ c.FileAttachment(localFilePath, filepath.Base(localFilePath))+}diff --git a/internal/router/router.go b/internal/router/router.goindex 841d6987..2d539f7f 100644--- a/internal/router/router.go+++ b/internal/router/router.go@@ -15,6 +15,7 @@ func SetupRouter(r *gin.Engine) {api.POST("/capability/subtitleTask", hdl.StartSubtitleTask)api.GET("/capability//subtitleTask", hdl.GetSubtitleTask)api.POST("/file", hdl.UploadFile)+ api.GET("/file/*filepath", hdl.DownloadFile)}r.GET("/", func(c *gin.Context) {diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.goindex 71169d96..1409a1d4 100644--- a/internal/service/subtitle_service.go+++ b/internal/service/subtitle_service.go@@ -587,7 +587,7 @@ func (s Service) splitSrt(ctx context.Context, stepParam *types.SubtitleTaskStep}// 添加原语言单语字幕subtitleInfo := types.SubtitleFileInfo{- Path: originLanguageSrtFilePath,+ Path: "/api/file/" + originLanguageSrtFilePath,LanguageIdentifier: string(stepParam.OriginLanguage),}if stepParam.UserUILanguage == types.LanguageNameEnglish {@@ -599,7 +599,7 @@ func (s Service) splitSrt(ctx context.Context, stepParam *types.SubtitleTaskStep// 添加目标语言单语字幕if stepParam.SubtitleResultType == types.SubtitleResultTypeTargetOnly || stepParam.SubtitleResultType == types.SubtitleResultTypeBilingualTranslationOnBottom || stepParam.SubtitleResultType == types.SubtitleResultTypeBilingualTranslationOnTop {subtitleInfo = types.SubtitleFileInfo{- Path: targetLanguageSrtFilePath,+ Path: "/api/file/" + targetLanguageSrtFilePath,LanguageIdentifier: string(stepParam.TargetLanguage),}if stepParam.UserUILanguage == types.LanguageNameEnglish {@@ -612,7 +612,7 @@ func (s Service) splitSrt(ctx context.Context, stepParam *types.SubtitleTaskStep// 添加双语字幕if stepParam.SubtitleResultType == types.SubtitleResultTypeBilingualTranslationOnTop || stepParam.SubtitleResultType == types.SubtitleResultTypeBilingualTranslationOnBottom {subtitleInfo = types.SubtitleFileInfo{- Path: stepParam.BilingualSrtFilePath,+ Path: "/api/file/" + stepParam.BilingualSrtFilePath,LanguageIdentifier: "bilingual",}if stepParam.UserUILanguage == types.LanguageNameEnglish {diff --git a/internal/types/subtitle_task.go b/internal/types/subtitle_task.goindex a5be8ee7..d0c9ef61 100644--- a/internal/types/subtitle_task.go+++ b/internal/types/subtitle_task.go@@ -1,7 +1,6 @@package typesimport (- "context""krillin-ai/pkg/openai")@@ -205,25 +204,6 @@ const (LanguageNameAlbanian StandardLanguageName = "sq")-type StepParam struct {- BasePath string- Uid uint32- TaskId string- VideoId string- AudioFile string- SmallAudios []*SmallAudio- OriginSrtNoTsFile string- SubtitleResultType SubtitleResultType- EnableModalFilter bool- ReplaceWordsMap map[string]string- OriginLanguage StandardLanguageName // 视频源语言- TargetLanguage StandardLanguageName // 用户希望的目标翻译语言- UserUILanguage StandardLanguageName // 用户的使用语言- TargetLanguageSrtFile string- OriginLanguageSrtFile string- BilingualSrtFile string-}-type SubtitleFileInfo struct {Name stringPath string@@ -250,8 +230,6 @@ type SubtitleTaskStepParam struct {TtsResultFilePath string}-type SubtitleTaskStepFunc func(ctx context.Context, stepParam *SubtitleTaskStepParam) error-type SrtSentence struct {Text stringStart float64