chore: opt settings code

This commit is contained in:
engigu
2025-12-21 10:23:25 +08:00
parent 432c57e862
commit c06030fe27
28 changed files with 535 additions and 187 deletions
+5 -4
View File
@@ -8,9 +8,10 @@ import (
var cronService *services.CronService
func RegisterControllers() (*Controllers, *services.SettingsService) {
func RegisterControllers() *Controllers {
// Initialize services
settingsService := services.NewSettingsService()
loginLogService := services.NewLoginLogService()
// 执行系统初始化(返回 userService
initService := services.NewInitService(settingsService)
@@ -28,7 +29,7 @@ func RegisterControllers() (*Controllers, *services.SettingsService) {
// Initialize and return controllers
return &Controllers{
Task: controllers.NewTaskController(taskService, cronService),
Auth: controllers.NewAuthController(userService, settingsService),
Auth: controllers.NewAuthController(userService, settingsService, loginLogService),
Env: controllers.NewEnvController(envService),
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
@@ -36,8 +37,8 @@ func RegisterControllers() (*Controllers, *services.SettingsService) {
Dashboard: controllers.NewDashboardController(cronService, executorService),
Log: controllers.NewLogController(),
Terminal: controllers.NewTerminalController(),
Settings: controllers.NewSettingsController(userService),
}, settingsService
Settings: controllers.NewSettingsController(userService, loginLogService),
}
}
// StopCron stops the cron service gracefully
+3 -3
View File
@@ -6,7 +6,6 @@ import (
"baihu/internal/controllers"
"baihu/internal/middleware"
"baihu/internal/services"
"baihu/internal/static"
"github.com/gin-gonic/gin"
@@ -41,7 +40,7 @@ func cacheControl(value string) gin.HandlerFunc {
}
}
func Setup(c *Controllers, settingsService *services.SettingsService) *gin.Engine {
func Setup(c *Controllers) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
router.Use(middleware.GinLogger(), middleware.GinRecovery())
@@ -95,7 +94,7 @@ func Setup(c *Controllers, settingsService *services.SettingsService) *gin.Engin
// 需要认证的路由
authorized := api.Group("")
authorized.Use(middleware.AuthRequired(settingsService))
authorized.Use(middleware.AuthRequired())
{
// 获取当前用户
authorized.GET("/auth/me", c.Auth.GetCurrentUser)
@@ -174,6 +173,7 @@ func Setup(c *Controllers, settingsService *services.SettingsService) *gin.Engin
settings.GET("/site", c.Settings.GetSiteSettings)
settings.PUT("/site", c.Settings.UpdateSiteSettings)
settings.GET("/about", c.Settings.GetAbout)
settings.GET("/login-logs", c.Settings.GetLoginLogs)
}
}
}