2801-есть десктоп-версия. реализован ws для авторизации через тг-бота

This commit is contained in:
2026-01-28 08:12:41 +03:00
parent a536b3ff3c
commit b99e328d35
26 changed files with 2258 additions and 82 deletions

View File

@@ -15,7 +15,9 @@ import (
"rmser/internal/infrastructure/ocr_client"
"rmser/internal/infrastructure/yookassa"
"rmser/internal/services/auth"
"rmser/internal/transport/http/middleware"
"rmser/internal/transport/ws"
tgBot "rmser/internal/transport/telegram"
// Repositories
@@ -56,6 +58,11 @@ func main() {
log.Fatalf("Ошибка загрузки конфига: %v", err)
}
// Проверяем, что bot_username задан в конфиге
if cfg.Telegram.BotUsername == "" {
log.Fatalf("Telegram.BotUsername не задан в конфиге! Это обязательное поле для авторизации.")
}
// 2. Logger
logger.Init(cfg.App.Mode)
defer logger.Log.Sync()
@@ -102,7 +109,14 @@ func main() {
invoicesService := invoicesServicePkg.NewService(invoicesRepo, draftsRepo, supplierRepo, rmsFactory)
photosService := photosServicePkg.NewService(photosRepo, draftsRepo, accountRepo)
// 7. Handlers
// 7. WebSocket сервер для desktop авторизации
wsServer := ws.NewServer()
go wsServer.Run()
// 8. Сервис авторизации для desktop auth
authService := auth.NewService(accountRepo, wsServer, cfg.Security.SecretKey)
// 9. Handlers
draftsHandler := handlers.NewDraftsHandler(draftsService)
billingHandler := handlers.NewBillingHandler(billingService)
ocrHandler := handlers.NewOCRHandler(ocrService)
@@ -110,10 +124,11 @@ func main() {
recommendHandler := handlers.NewRecommendationsHandler(recService)
settingsHandler := handlers.NewSettingsHandler(accountRepo, catalogRepo)
invoicesHandler := handlers.NewInvoiceHandler(invoicesService, syncService)
authHandler := handlers.NewAuthHandler(authService, cfg.Telegram.BotUsername)
// 8. Telegram Bot (Передаем syncService)
// 10. Telegram Bot (Передаем syncService и authService)
if cfg.Telegram.Token != "" {
bot, err := tgBot.NewBot(cfg.Telegram, ocrService, syncService, billingService, accountRepo, rmsFactory, cryptoManager, draftsService, cfg.App.MaintenanceMode, cfg.App.DevIDs)
bot, err := tgBot.NewBot(cfg.Telegram, ocrService, syncService, billingService, accountRepo, rmsFactory, cryptoManager, draftsService, authService, cfg.App.MaintenanceMode, cfg.App.DevIDs)
if err != nil {
logger.Log.Fatal("Ошибка создания Telegram бота", zap.Error(err))
}
@@ -125,12 +140,15 @@ func main() {
defer bot.Stop()
}
// 9. HTTP Server
// 11. HTTP Server
if cfg.App.Mode == "release" {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
// Регистрируем WebSocket хендлер
r.GET("/socket.io/", wsServer.HandleConnections)
r.POST("/api/webhooks/yookassa", billingHandler.YooKassaWebhook)
corsConfig := cors.DefaultConfig()
@@ -145,7 +163,10 @@ func main() {
api := r.Group("/api")
api.Use(middleware.AuthMiddleware(accountRepo, cfg.Telegram.Token, cfg.App.MaintenanceMode, cfg.App.DevIDs))
// Хендлер инициализации desktop авторизации (без middleware)
api.POST("/auth/init-desktop", authHandler.InitDesktopAuth)
api.Use(middleware.AuthMiddleware(accountRepo, cfg.Telegram.Token, cfg.Security.SecretKey, cfg.App.MaintenanceMode, cfg.App.DevIDs))
{
// Drafts & Invoices
api.GET("/drafts", draftsHandler.GetDrafts)