diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index fcfa4151..bdb1ed3a 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -12,6 +12,7 @@ import ( "github.com/momshell/backend/internal/model" "github.com/momshell/backend/internal/repository" "github.com/momshell/backend/internal/router" + "github.com/momshell/backend/internal/scheduler" "github.com/momshell/backend/internal/service" "github.com/momshell/backend/pkg/firecrawl" "github.com/momshell/backend/pkg/openai" @@ -75,7 +76,7 @@ func main() { chatService := service.NewChatService(chatClient, chatRepo, firecrawlClient) echoService := service.NewEchoService(chatClient, echoRepo, userRepo) - photoService := service.NewPhotoService(photoRepo, chatClient, cfg.ImageModel) + photoService := service.NewPhotoService(photoRepo, userRepo, chatClient, cfg.ImageModel) whisperService := service.NewWhisperService(whisperRepo, userRepo, chatClient) taskService := service.NewTaskService(taskRepo, userRepo) @@ -97,10 +98,13 @@ func main() { // Initialize admin layer adminRepo := repository.NewAdminRepo(db) - adminService := service.NewAdminService(cfg, adminRepo, userRepo) + adminService := service.NewAdminService(cfg, adminRepo, userRepo, photoRepo) + + // Start background schedulers + scheduler.StartPhotoCleanup(photoRepo) // Initialize handlers - authHandler := handler.NewAuthHandler(authService) + authHandler := handler.NewAuthHandler(authService, cfg) questionHandler := handler.NewQuestionHandler(communityService, authService, communityAIService) answerHandler := handler.NewAnswerHandler(communityService, authService, communityAIService) commentHandler := handler.NewCommentHandler(communityService, authService, communityAIService) @@ -116,13 +120,16 @@ func main() { // Setup Gin r := gin.New() + _ = r.SetTrustedProxies(nil) // Don't trust any proxy headers by default r.Use(middleware.Recovery()) - r.Use(middleware.CORS()) + r.Use(middleware.SecurityHeaders()) + r.Use(middleware.CORS(cfg)) r.Use(gin.Logger()) // Register routes router.Setup( r, cfg, + adminHandler.IsAdmin, authHandler, questionHandler, answerHandler, commentHandler, interactionHandler, tagHandler, chatHandler, echoHandler, userHandler, adminHandler, diff --git a/backend/internal/admin/admin.html b/backend/internal/admin/admin.html index 2db5bdf6..3528ed29 100644 --- a/backend/internal/admin/admin.html +++ b/backend/internal/admin/admin.html @@ -4,8 +4,8 @@ MomShell 管理面板 - - + +