feat: add notify icon read
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"time"
|
||||
|
||||
// "github.com/engigu/baihu-panel/internal/constant"
|
||||
"github.com/engigu/baihu-panel/internal/eventbus"
|
||||
// "github.com/engigu/baihu-panel/internal/logger"
|
||||
// "github.com/engigu/baihu-panel/internal/models"
|
||||
"github.com/engigu/baihu-panel/internal/services"
|
||||
)
|
||||
|
||||
func setupEventHandlers(subscribers ...eventbus.Subscriber) {
|
||||
bus := eventbus.DefaultBus
|
||||
|
||||
// 遍历并统一初始化所有订阅者的事件链路
|
||||
for _, s := range subscribers {
|
||||
s.SubscribeEvents(bus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func startAppLogCleanup(appLogSvc *services.AppLogService) {
|
||||
// 初始化时执行一次清理
|
||||
appLogSvc.CleanUp()
|
||||
|
||||
// 每天凌晨或者定期清理
|
||||
ticker := time.NewTicker(24 * time.Hour)
|
||||
for range ticker.C {
|
||||
appLogSvc.CleanUp()
|
||||
}
|
||||
}
|
||||
@@ -26,17 +26,23 @@ func RegisterControllers() *Controllers {
|
||||
|
||||
taskLogService := tasks.NewTaskLogService(sendStatsService)
|
||||
// 创建任务执行服务(需要依赖注入)
|
||||
notifyService := services.NewNotificationService()
|
||||
appLogService := services.NewAppLogService()
|
||||
|
||||
// 清理 task 运行状态的任务可以直接由 executorService 承担或在此处通过 Database 直接清理
|
||||
// 简单期间,我们使用一个新方法 tasks.CleanupRunningTasks() 或者让 executorService 启动时清理
|
||||
|
||||
executorService = tasks.NewExecutorService(taskService, taskLogService, agentWSManager, settingsService, envService, services.NewNotificationService())
|
||||
executorService = tasks.NewExecutorService(taskService, taskLogService, agentWSManager, settingsService, envService)
|
||||
// 启动时清理残留的运行状态
|
||||
_ = executorService.CleanupRunningTasks()
|
||||
|
||||
// 启动计划任务
|
||||
executorService.StartCron()
|
||||
|
||||
// 初始化所有关注系统总线的服务
|
||||
setupEventHandlers(appLogService, notifyService, loginLogService)
|
||||
go startAppLogCleanup(appLogService)
|
||||
|
||||
// 初始化并返回控制器
|
||||
return &Controllers{
|
||||
Task: controllers.NewTaskController(taskService, executorService),
|
||||
@@ -54,6 +60,7 @@ func RegisterControllers() *Controllers {
|
||||
Agent: controllers.NewAgentController(settingsService),
|
||||
Mise: controllers.NewMiseController(services.NewMiseService()),
|
||||
Notification: controllers.NewNotificationController(),
|
||||
AppLog: controllers.NewAppLogController(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ type Controllers struct {
|
||||
Agent *controllers.AgentController
|
||||
Mise *controllers.MiseController
|
||||
Notification *controllers.NotificationController
|
||||
AppLog *controllers.AppLogController
|
||||
}
|
||||
|
||||
func mustSubFS(fsys fs.FS, dir string) fs.FS {
|
||||
@@ -249,6 +250,7 @@ func initAuthorizedAPIRoutes(api *gin.RouterGroup, c *Controllers) {
|
||||
registerAgentRoutes(authorized, c)
|
||||
registerMiseRoutes(authorized, c)
|
||||
registerNotificationRoutes(authorized, c)
|
||||
registerAppLogRoutes(authorized, c)
|
||||
}
|
||||
|
||||
// 通知发送 API(使用通知 Token 认证,供脚本调用)
|
||||
@@ -421,6 +423,15 @@ func registerNotificationRoutes(g *gin.RouterGroup, c *Controllers) {
|
||||
}
|
||||
}
|
||||
|
||||
func registerAppLogRoutes(g *gin.RouterGroup, c *Controllers) {
|
||||
appLogs := g.Group("/app-logs")
|
||||
{
|
||||
appLogs.GET("", c.AppLog.GetLogs)
|
||||
appLogs.POST("/read", c.AppLog.MarkAsRead)
|
||||
appLogs.POST("/clear", c.AppLog.ClearLogs)
|
||||
}
|
||||
}
|
||||
|
||||
func initAgentAPIRoutes(root *gin.RouterGroup, c *Controllers) {
|
||||
// Agent API(供远程 Agent 调用,不使用 /v1 版本号)
|
||||
agentAPI := root.Group("/api/agent")
|
||||
|
||||
Reference in New Issue
Block a user