add getting drive url and save it, and use it in saving fields type file

This commit is contained in:
Pavel 2024-06-08 18:13:09 +03:00
parent e3a390617a
commit 2b7e7fa945
8 changed files with 18 additions and 14 deletions

2
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 (

4
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=

@ -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{

@ -25,7 +25,7 @@ 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"`
//AmoStorageURL string `env:"AMO_STORAGE_URL" envDefault:"https://drive-b.amocrm.ru"`
RedirectURL string `env:"REDIRECT_URL" envDefault:"https://squiz.pena.digital/integrations"`
}

@ -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
}

@ -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)

@ -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:

@ -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))