added save to slice active tg clients and to db for restore

This commit is contained in:
Pavel 2024-07-01 11:53:42 +03:00
parent fec5374964
commit 51aa0e4aee
2 changed files with 13 additions and 8 deletions

6
go.sum

@ -289,12 +289,6 @@ penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240627194440-f99
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240627194440-f997b952c31f/go.mod h1:uOuosXduBzd2WbLH6TDZO7ME7ZextulA662oZ6OsoB0=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990 h1:jiO8GWO+3sCnDAV8/NAV8tQIUwae/I6/xiDilW7zf0o=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990/go.mod h1:zswBuTwmEsFHBVRu1nkG3/Fwylk5Vcm8OUm9iWxccSE=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240630165148-3c27e15d9ac1 h1:fGhu5JuLODJ4pLb4YiyrioFXSQS+UP+KUQhcLwzIeWs=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240630165148-3c27e15d9ac1/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701074825-8eceb99cd2ab h1:axHShcqrVZHx6CTB0OJW8ac3Hqi7DxfJu2e5nuusxE4=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701074825-8eceb99cd2ab/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075500-8c122317a246 h1:FRQfWwaSJB2eyp8eTNdulg5/V2bC1VnmC6YcGm7mYZg=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075500-8c122317a246/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075856-1731684c936f h1:Qli89wgu0T7nG4VECXZOZ40fjE/hVVfxF3hTaSYS008=
penahub.gitlab.yandexcloud.net/backend/tdlib v0.0.0-20240701075856-1731684c936f/go.mod h1:AkE19hcbDwB7hoEASwImm7rUI+cK/8jMVJaTvMK4F+c=
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240615192328-b2f5dffe92ae h1:vlGInCsQSDA464q7OMv3EWGUviQWQdEcpLc8HIRo+rE=

@ -5,6 +5,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/rs/xid"
"path/filepath"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/core/clients/telegram"
"penahub.gitlab.yandexcloud.net/backend/tdlib/client"
)
@ -18,7 +19,6 @@ func (s *Service) GetPoolTgAccounts(ctx *fiber.Ctx) error {
return nil
}
// todo save to slice and save to db for rewoke
func (s *Service) AddingTgAccount(ctx *fiber.Ctx) error {
var req telegram.AuthTgUserReq
if err := ctx.BodyParser(&req); err != nil {
@ -109,7 +109,18 @@ func (s *Service) SettingTgCode(ctx *fiber.Ctx) error {
fmt.Println("currnet state:", state)
switch state.AuthorizationStateType() {
case client.TypeAuthorizationStateReady:
return ctx.Status(fiber.StatusOK).SendString("auth success")
s.telegramClient.TgClients = append(s.telegramClient.TgClients, data.TdLibClient)
id, err := s.dal.TgRepo.CreateTgAccount(ctx.Context(), model.TgAccount{
ApiID: data.PreviousReq.ApiID,
ApiHash: data.PreviousReq.ApiHash,
PhoneNumber: data.PreviousReq.PhoneNumber,
Status: model.ActiveTg,
Password: data.PreviousReq.Password,
})
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
return ctx.Status(fiber.StatusOK).JSON(fiber.Map{"id": id})
case client.TypeAuthorizationStateWaitPassword:
data.Authorizer.Password <- data.PreviousReq.Password
case client.TypeAuthorizationStateLoggingOut, client.TypeAuthorizationStateClosing, client.TypeAuthorizationStateClosed: