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
feat: detect configuration updates and reinitialize affected services
puji481034b8beaa8137
diff --git a/internal/handler/config.go b/internal/handler/config.goindex 6989267d..eb2ae3c1 100644--- a/internal/handler/config.go+++ b/internal/handler/config.go@@ -9,6 +9,9 @@ import ("go.uber.org/zap")+// 全局变量,用于标记配置是否需要重新初始化+var configUpdated bool+// ConfigRequest 定义前端发送的配置数据结构type ConfigRequest struct {App struct {@@ -170,9 +173,12 @@ func (h Handler) UpdateConfig(c *gin.Context) {log.GetLogger().Info("更新配置信息")- // 备份当前配置+ // 更新配置备份,确保桌面应用能检测到配置变化config.ConfigBackup = config.Conf+ // 标记配置已更新,需要重新初始化服务+ configUpdated = true+// 更新应用配置config.Conf.App.SegmentDuration = req.App.SegmentDurationconfig.Conf.App.TranscribeParallelNum = req.App.TranscribeParallelNumdiff --git a/internal/handler/subtitle_task.go b/internal/handler/subtitle_task.goindex 15a2adaa..71acab46 100644--- a/internal/handler/subtitle_task.go+++ b/internal/handler/subtitle_task.go@@ -1,13 +1,16 @@package handlerimport (- "github.com/gin-gonic/gin"- "go.uber.org/zap""krillin-ai/internal/dto""krillin-ai/internal/response"+ "krillin-ai/internal/service"+ "krillin-ai/internal/deps""krillin-ai/log""os""path/filepath"++ "github.com/gin-gonic/gin"+ "go.uber.org/zap")func (h Handler) StartSubtitleTask(c *gin.Context) {@@ -22,6 +25,14 @@ func (h Handler) StartSubtitleTask(c *gin.Context) {return}+ // 检查配置是否需要重新初始化+ if configUpdated {+ log.GetLogger().Info("检测到配置更新,重新初始化服务")+ deps.CheckDependency()+ h.Service = service.NewService()+ configUpdated = false+ }+svc := h.Servicedata, err := svc.StartSubtitleTask(req)@@ -50,6 +61,14 @@ func (h Handler) GetSubtitleTask(c *gin.Context) {})return}++ // 检查配置是否需要重新初始化+ if configUpdated {+ log.GetLogger().Info("检测到配置更新,重新初始化服务")+ h.Service = service.NewService()+ configUpdated = false+ }+svc := h.Servicedata, err := svc.GetTaskStatus(req)if err != nil {