feat: apply user settings to effect

This commit is contained in:
engigu
2025-12-20 13:30:08 +08:00
parent 07d988cc7e
commit a4d73a6f89
17 changed files with 168 additions and 111 deletions
+9 -9
View File
@@ -8,18 +8,18 @@ import (
var cronService *services.CronService
func RegisterControllers() *Controllers {
func RegisterControllers() (*Controllers, *services.SettingsService) {
// Initialize services
settingsService := services.NewSettingsService()
// 执行系统初始化(返回 userService
initService := services.NewInitService(settingsService)
userService := initService.Initialize()
taskService := services.NewTaskService()
userService := services.NewUserService()
envService := services.NewEnvService()
scriptService := services.NewScriptService()
executorService := services.NewExecutorService(taskService)
settingsService := services.NewSettingsService()
// 执行系统初始化
initService := services.NewInitService(settingsService, userService)
initService.Initialize()
// Initialize cron service
cronService = services.NewCronService(taskService, executorService)
@@ -28,7 +28,7 @@ func RegisterControllers() *Controllers {
// Initialize and return controllers
return &Controllers{
Task: controllers.NewTaskController(taskService, cronService),
Auth: controllers.NewAuthController(userService),
Auth: controllers.NewAuthController(userService, settingsService),
Env: controllers.NewEnvController(envService),
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
@@ -37,7 +37,7 @@ func RegisterControllers() *Controllers {
Log: controllers.NewLogController(),
Terminal: controllers.NewTerminalController(),
Settings: controllers.NewSettingsController(userService),
}
}, settingsService
}
// StopCron stops the cron service gracefully
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"baihu/internal/controllers"
"baihu/internal/middleware"
"baihu/internal/services"
"baihu/internal/static"
"github.com/gin-gonic/gin"
@@ -40,7 +41,7 @@ func cacheControl(value string) gin.HandlerFunc {
}
}
func Setup(c *Controllers) *gin.Engine {
func Setup(c *Controllers, settingsService *services.SettingsService) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
router.Use(middleware.GinLogger(), middleware.GinRecovery())
@@ -94,7 +95,7 @@ func Setup(c *Controllers) *gin.Engine {
// 需要认证的路由
authorized := api.Group("")
authorized.Use(middleware.AuthRequired())
authorized.Use(middleware.AuthRequired(settingsService))
{
// 获取当前用户
authorized.GET("/auth/me", c.Auth.GetCurrentUser)