feat(modpack): modpack updates

This commit is contained in:
2025-06-18 18:18:16 +03:00
parent 2c682c5123
commit 96fb472497
4 changed files with 121 additions and 19 deletions

View File

@@ -15,26 +15,18 @@ import (
)
func main() {
// Инициализируем соединение с БД
dbPool := database.Connect()
defer dbPool.Close()
// --- Инициализация репозиториев ---
userRepo := &database.UserRepository{DB: dbPool}
serverRepo := &database.ServerRepository{DB: dbPool}
modpackRepo := &database.ModpackRepository{DB: dbPool}
serverPoller := &core.ServerPoller{Repo: serverRepo}
modpackHandler := &api.ModpackHandler{ModpackRepo: modpackRepo}
launcherHandler := &api.LauncherHandler{ModpackRepo: modpackRepo}
adminUserHandler := &api.AdminUserHandler{UserRepo: userRepo}
// Запускаем поллер в фоновой горутине
go serverPoller.Start(context.Background())
// Сервисы
// --- Инициализация сервисов ---
userService := &core.UserService{Repo: userRepo}
authService := &core.AuthService{UserRepo: userRepo}
serverPoller := &core.ServerPoller{Repo: serverRepo}
keyPath := os.Getenv("RSA_PRIVATE_KEY_PATH")
if keyPath == "" {
@@ -48,12 +40,29 @@ func main() {
if err != nil {
log.Fatalf("Failed to create profile service: %v", err)
}
// Хендлеры
modpacksStoragePath := os.Getenv("MODPACKS_STORAGE_PATH")
if modpacksStoragePath == "" {
log.Fatal("MODPACKS_STORAGE_PATH environment variable is not set")
}
janitorService := core.NewFileJanitorService(modpackRepo, modpacksStoragePath)
// --- Запуск фоновых задач ---
go serverPoller.Start(context.Background())
// --- Инициализация хендлеров ---
userHandler := &api.UserHandler{Service: userService}
authHandler := &api.AuthHandler{Service: authService}
profileHandler := &api.ProfileHandler{Service: profileService}
serverHandler := &api.ServerHandler{Repo: serverRepo}
// --- Настраиваем роутер ---
launcherHandler := &api.LauncherHandler{ModpackRepo: modpackRepo}
modpackHandler := &api.ModpackHandler{
ModpackRepo: modpackRepo,
JanitorService: janitorService,
}
adminUserHandler := &api.AdminUserHandler{UserRepo: userRepo} // Этот хендлер мы создали для админских функций
// --- Настройка роутера ---
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
@@ -63,6 +72,10 @@ func main() {
r.Post("/register", userHandler.Register)
r.Post("/login", authHandler.Login)
r.Get("/servers", serverHandler.GetServers)
r.Route("/launcher", func(r chi.Router) {
r.Get("/modpacks/{name}/manifest", launcherHandler.GetModpackManifest)
})
})
r.Route("/authserver", func(r chi.Router) {
r.Post("/authenticate", authHandler.Authenticate)
@@ -71,23 +84,24 @@ func main() {
r.Post("/join", authHandler.Join)
r.Get("/profile/{uuid}", profileHandler.GetProfile)
})
r.Route("/launcher", func(r chi.Router) {
r.Get("/modpacks/{name}/manifest", launcherHandler.GetModpackManifest)
})
// --- Защищенные роуты ---
r.Group(func(r chi.Router) {
r.Use(api.AuthMiddleware) // TODO: Заменить на AdminMiddleware
r.Use(api.AuthMiddleware)
r.Route("/api/user", func(r chi.Router) {
r.Post("/skin", profileHandler.UploadSkin)
})
r.Route("/api/admin", func(r chi.Router) {
r.Use(api.AdminMiddleware)
r.Route("/modpacks", func(r chi.Router) {
r.Post("/import", modpackHandler.ImportModpack)
})
r.Route("/users", func(r chi.Router) {
// ИСПРАВЛЕНО: Используем adminUserHandler
r.Get("/", adminUserHandler.GetAllUsers)
r.Patch("/{id}/role", adminUserHandler.UpdateUserRole)
})