feat: add message push function call

This commit is contained in:
engigu
2026-03-04 21:45:43 +08:00
parent d4663cb492
commit 81b8d2a93d
53 changed files with 4161 additions and 33 deletions
+16 -15
View File
@@ -30,7 +30,7 @@ func RegisterControllers() *Controllers {
// 清理 task 运行状态的任务可以直接由 executorService 承担或在此处通过 Database 直接清理
// 简单期间,我们使用一个新方法 tasks.CleanupRunningTasks() 或者让 executorService 启动时清理
executorService = tasks.NewExecutorService(taskService, taskLogService, agentWSManager, settingsService, envService)
executorService = tasks.NewExecutorService(taskService, taskLogService, agentWSManager, settingsService, envService, services.NewNotificationService())
// 启动时清理残留的运行状态
_ = executorService.CleanupRunningTasks()
@@ -39,20 +39,21 @@ func RegisterControllers() *Controllers {
// 初始化并返回控制器
return &Controllers{
Task: controllers.NewTaskController(taskService, executorService),
Auth: controllers.NewAuthController(userService, settingsService, loginLogService),
Env: controllers.NewEnvController(envService),
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
File: controllers.NewFileController(constant.ScriptsWorkDir),
Dashboard: controllers.NewDashboardController(executorService),
Log: controllers.NewLogController(),
LogWS: controllers.NewLogWSController(),
Terminal: controllers.NewTerminalController(envService),
Settings: controllers.NewSettingsController(userService, loginLogService, executorService),
Dependency: controllers.NewDependencyController(),
Agent: controllers.NewAgentController(settingsService),
Mise: controllers.NewMiseController(services.NewMiseService()),
Task: controllers.NewTaskController(taskService, executorService),
Auth: controllers.NewAuthController(userService, settingsService, loginLogService),
Env: controllers.NewEnvController(envService),
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
File: controllers.NewFileController(constant.ScriptsWorkDir),
Dashboard: controllers.NewDashboardController(executorService),
Log: controllers.NewLogController(),
LogWS: controllers.NewLogWSController(),
Terminal: controllers.NewTerminalController(envService),
Settings: controllers.NewSettingsController(userService, loginLogService, executorService),
Dependency: controllers.NewDependencyController(),
Agent: controllers.NewAgentController(settingsService),
Mise: controllers.NewMiseController(services.NewMiseService()),
Notification: controllers.NewNotificationController(),
}
}
+26 -2
View File
@@ -26,8 +26,9 @@ type Controllers struct {
Terminal *controllers.TerminalController
Settings *controllers.SettingsController
Dependency *controllers.DependencyController
Agent *controllers.AgentController
Mise *controllers.MiseController
Agent *controllers.AgentController
Mise *controllers.MiseController
Notification *controllers.NotificationController
}
func mustSubFS(fsys fs.FS, dir string) fs.FS {
@@ -199,6 +200,9 @@ func Setup(c *Controllers) *gin.Engine {
settings.GET("/backup/status", c.Settings.GetBackupStatus)
settings.GET("/backup/download", c.Settings.DownloadBackup)
settings.POST("/restore", c.Settings.RestoreBackup)
// 通用设置接口
settings.GET("/:section/:key", c.Settings.GetSetting)
settings.POST("/:section/:key/generate", c.Settings.GenerateSettingToken)
}
// Dependency routes (依赖管理)
@@ -246,6 +250,26 @@ func Setup(c *Controllers) *gin.Engine {
{
agentAPIv1.GET("/download", c.Agent.Download)
}
// 通知推送模块
notify := authorized.Group("/notify")
{
notify.GET("/types", c.Notification.GetChannelTypes)
notify.GET("/channels", c.Notification.GetChannels)
notify.POST("/channels", c.Notification.SaveChannel)
notify.DELETE("/channels/:id", c.Notification.DeleteChannel)
notify.POST("/channels/test", c.Notification.TestChannel)
notify.GET("/bindings", c.Notification.GetBindings)
notify.POST("/bindings", c.Notification.SaveBinding)
notify.DELETE("/bindings/:id", c.Notification.DeleteBinding)
}
}
// 通知发送 API(使用通知 Token 认证,供脚本调用)
notifyAPI := api.Group("/notify")
notifyAPI.Use(middleware.NotifyTokenAuth())
{
notifyAPI.POST("/send", c.Notification.SendNotification)
}
}