diff --git a/go.mod b/go.mod index b582abe..44f1ac9 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/twmb/franz-go v1.16.1 go.uber.org/zap v1.27.0 google.golang.org/protobuf v1.33.0 - penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608142718-74ecde46ec07 + penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608150318-7e16f4547ed5 ) require ( diff --git a/go.sum b/go.sum index 20cc91c..99ed76e 100644 --- a/go.sum +++ b/go.sum @@ -134,5 +134,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608142718-74ecde46ec07 h1:/v4ybgqkUZc08ozu2OC5nMcJIzyYwsUlH6IK7pePsQk= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608142718-74ecde46ec07/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608150318-7e16f4547ed5 h1:Sn/XyY0Kf2sH/3nViSlsi7EzfGqhW9luNkiUyi8Tick= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608150318-7e16f4547ed5/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398= diff --git a/internal/app/app.go b/internal/app/app.go index 5d5451b..5efbe90 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -76,7 +76,6 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro IntegrationID: config.IntegrationID, IntegrationSecret: config.IntegrationSecret, RateLimiter: rateLimiter, - AmoStorageURL: config.AmoStorageURL, }) redisRepo := repository.NewRepository(repository.Deps{ diff --git a/internal/initialize/config.go b/internal/initialize/config.go index 5b403bd..f90faf7 100644 --- a/internal/initialize/config.go +++ b/internal/initialize/config.go @@ -25,8 +25,8 @@ type Config struct { IntegrationID string `env:"INTEGRATION_ID" envDefault:"2dbd6329-9be6-41f2-aa5f-964b9e723e49"` // секрет интеграции IntegrationSecret string `env:"INTEGRATION_SECRET" envDefault:"tNK3LwL4ovP0OBK4jKDHJ3646PqRJDOKQYgY6P2t6DCuV8LEzDzszTDY0Fhwmzc8"` - AmoStorageURL string `env:"AMO_STORAGE_URL" envDefault:"https://drive-b.amocrm.ru"` - RedirectURL string `env:"REDIRECT_URL" envDefault:"https://squiz.pena.digital/integrations"` + //AmoStorageURL string `env:"AMO_STORAGE_URL" envDefault:"https://drive-b.amocrm.ru"` + RedirectURL string `env:"REDIRECT_URL" envDefault:"https://squiz.pena.digital/integrations"` } func LoadConfig() (*Config, error) { diff --git a/internal/workers/post_deals_worker/deals_worker.go b/internal/workers/post_deals_worker/deals_worker.go index e8880f6..77aaeb4 100644 --- a/internal/workers/post_deals_worker/deals_worker.go +++ b/internal/workers/post_deals_worker/deals_worker.go @@ -240,8 +240,8 @@ func (wc *PostDeals) constructField(ctx context.Context, allAnswers []model.Resu continue } - if fieldData.Type == model.TypeFile && data.Content != "" { - value, err := wc.amoClient.UploadFileToAmo(data.Content, result.AccessToken) + if fieldData.Type == model.TypeFile && data.Content != "" && result.DriveURL != "" { + value, err := wc.amoClient.UploadFileToAmo(data.Content, result.AccessToken, result.DriveURL) if err != nil { return nil, nil, nil, nil, err } diff --git a/internal/workers_methods/methods.go b/internal/workers_methods/methods.go index 7ddc2da..afd6592 100644 --- a/internal/workers_methods/methods.go +++ b/internal/workers_methods/methods.go @@ -523,6 +523,7 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, msg models.KafkaMes AmoID: userInfo.ID, Amouserid: userInfo.ID, Country: userInfo.Country, + DriveURL: userInfo.DriveUrl, } err = m.repo.AmoRepo.CreateAccount(ctx, msg.AccountID, toCreate) diff --git a/openapi.yaml b/openapi.yaml index 6adead3..58e04ed 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -784,6 +784,10 @@ components: Country: type: string description: страна указанная в настройках аккаунта амо + DriveURL: + type: string + description: урл объектного хранилища пользователя в амо, возвращается только в методе получения текущего аккаунта + ConnectAccountResp: type: object properties: @@ -817,6 +821,9 @@ components: CreatedAt: type: integer description: таймштамп создания аккаунта + DriveURL: + type: string + description: урл объектного хранилища пользователя в амо, возвращается только в методе получения текущего аккаунта GetListUserUTMResp: type: object properties: diff --git a/pkg/amoClient/amo.go b/pkg/amoClient/amo.go index a211d91..8d0fb6f 100644 --- a/pkg/amoClient/amo.go +++ b/pkg/amoClient/amo.go @@ -26,7 +26,6 @@ type Amo struct { integrationID string integrationSecret string rateLimiter *limiter.RateLimiter - amoStorageURL string fileMutex sync.Mutex } @@ -37,7 +36,6 @@ type AmoDeps struct { IntegrationID string IntegrationSecret string RateLimiter *limiter.RateLimiter - AmoStorageURL string } func NewAmoClient(deps AmoDeps) *Amo { @@ -51,7 +49,6 @@ func NewAmoClient(deps AmoDeps) *Amo { integrationSecret: deps.IntegrationSecret, integrationID: deps.IntegrationID, rateLimiter: deps.RateLimiter, - amoStorageURL: deps.AmoStorageURL, } } @@ -280,7 +277,7 @@ func (a *Amo) GetListTags(req models.GetListTagsReq, accessToken string, domain func (a *Amo) GetUserInfo(accessToken string, domain string) (*models.AmocrmUserInformation, error) { for { if a.rateLimiter.Check() { - url := fmt.Sprintf("https://%s/api/v4/account", domain) + url := fmt.Sprintf("https://%s/api/v4/account?with=drive_url", domain) agent := a.fiberClient.Get(url) agent.Set("Authorization", "Bearer "+accessToken) statusCode, resBody, errs := agent.Bytes() @@ -577,7 +574,7 @@ func (a *Amo) downloadFile(urlFile string) (*os.File, error) { return tmpFile, nil } -func (a *Amo) UploadFileToAmo(urlFile string, accessToken string) (*models.ValuesFile, error) { +func (a *Amo) UploadFileToAmo(urlFile string, accessToken string, driveURL string) (*models.ValuesFile, error) { a.fileMutex.Lock() defer a.fileMutex.Unlock() localFile, err := a.downloadFile(urlFile) @@ -598,7 +595,7 @@ func (a *Amo) UploadFileToAmo(urlFile string, accessToken string) (*models.Value FileSize: fileSize, } - uri := fmt.Sprintf("%s/v1.0/sessions", a.amoStorageURL) + uri := fmt.Sprintf("%s/v1.0/sessions", driveURL) bodyBytes, err := json.Marshal(createSessionData) if err != nil { a.logger.Error("error marshal create session data:", zap.Error(err))