add getting drive url and save it, and use it in saving fields type file
This commit is contained in:
parent
e3a390617a
commit
2b7e7fa945
2
go.mod
2
go.mod
@ -13,7 +13,7 @@ require (
|
|||||||
github.com/twmb/franz-go v1.16.1
|
github.com/twmb/franz-go v1.16.1
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
google.golang.org/protobuf v1.33.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 (
|
require (
|
||||||
|
4
go.sum
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=
|
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 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/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-20240608150318-7e16f4547ed5 h1:Sn/XyY0Kf2sH/3nViSlsi7EzfGqhW9luNkiUyi8Tick=
|
||||||
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/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||||
|
@ -76,7 +76,6 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
|||||||
IntegrationID: config.IntegrationID,
|
IntegrationID: config.IntegrationID,
|
||||||
IntegrationSecret: config.IntegrationSecret,
|
IntegrationSecret: config.IntegrationSecret,
|
||||||
RateLimiter: rateLimiter,
|
RateLimiter: rateLimiter,
|
||||||
AmoStorageURL: config.AmoStorageURL,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
redisRepo := repository.NewRepository(repository.Deps{
|
redisRepo := repository.NewRepository(repository.Deps{
|
||||||
|
@ -25,8 +25,8 @@ type Config struct {
|
|||||||
IntegrationID string `env:"INTEGRATION_ID" envDefault:"2dbd6329-9be6-41f2-aa5f-964b9e723e49"`
|
IntegrationID string `env:"INTEGRATION_ID" envDefault:"2dbd6329-9be6-41f2-aa5f-964b9e723e49"`
|
||||||
// секрет интеграции
|
// секрет интеграции
|
||||||
IntegrationSecret string `env:"INTEGRATION_SECRET" envDefault:"tNK3LwL4ovP0OBK4jKDHJ3646PqRJDOKQYgY6P2t6DCuV8LEzDzszTDY0Fhwmzc8"`
|
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"`
|
RedirectURL string `env:"REDIRECT_URL" envDefault:"https://squiz.pena.digital/integrations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
|
@ -240,8 +240,8 @@ func (wc *PostDeals) constructField(ctx context.Context, allAnswers []model.Resu
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if fieldData.Type == model.TypeFile && data.Content != "" {
|
if fieldData.Type == model.TypeFile && data.Content != "" && result.DriveURL != "" {
|
||||||
value, err := wc.amoClient.UploadFileToAmo(data.Content, result.AccessToken)
|
value, err := wc.amoClient.UploadFileToAmo(data.Content, result.AccessToken, result.DriveURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,7 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, msg models.KafkaMes
|
|||||||
AmoID: userInfo.ID,
|
AmoID: userInfo.ID,
|
||||||
Amouserid: userInfo.ID,
|
Amouserid: userInfo.ID,
|
||||||
Country: userInfo.Country,
|
Country: userInfo.Country,
|
||||||
|
DriveURL: userInfo.DriveUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.repo.AmoRepo.CreateAccount(ctx, msg.AccountID, toCreate)
|
err = m.repo.AmoRepo.CreateAccount(ctx, msg.AccountID, toCreate)
|
||||||
|
@ -784,6 +784,10 @@ components:
|
|||||||
Country:
|
Country:
|
||||||
type: string
|
type: string
|
||||||
description: страна указанная в настройках аккаунта амо
|
description: страна указанная в настройках аккаунта амо
|
||||||
|
DriveURL:
|
||||||
|
type: string
|
||||||
|
description: урл объектного хранилища пользователя в амо, возвращается только в методе получения текущего аккаунта
|
||||||
|
|
||||||
ConnectAccountResp:
|
ConnectAccountResp:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -817,6 +821,9 @@ components:
|
|||||||
CreatedAt:
|
CreatedAt:
|
||||||
type: integer
|
type: integer
|
||||||
description: таймштамп создания аккаунта
|
description: таймштамп создания аккаунта
|
||||||
|
DriveURL:
|
||||||
|
type: string
|
||||||
|
description: урл объектного хранилища пользователя в амо, возвращается только в методе получения текущего аккаунта
|
||||||
GetListUserUTMResp:
|
GetListUserUTMResp:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -26,7 +26,6 @@ type Amo struct {
|
|||||||
integrationID string
|
integrationID string
|
||||||
integrationSecret string
|
integrationSecret string
|
||||||
rateLimiter *limiter.RateLimiter
|
rateLimiter *limiter.RateLimiter
|
||||||
amoStorageURL string
|
|
||||||
fileMutex sync.Mutex
|
fileMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +36,6 @@ type AmoDeps struct {
|
|||||||
IntegrationID string
|
IntegrationID string
|
||||||
IntegrationSecret string
|
IntegrationSecret string
|
||||||
RateLimiter *limiter.RateLimiter
|
RateLimiter *limiter.RateLimiter
|
||||||
AmoStorageURL string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAmoClient(deps AmoDeps) *Amo {
|
func NewAmoClient(deps AmoDeps) *Amo {
|
||||||
@ -51,7 +49,6 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
|||||||
integrationSecret: deps.IntegrationSecret,
|
integrationSecret: deps.IntegrationSecret,
|
||||||
integrationID: deps.IntegrationID,
|
integrationID: deps.IntegrationID,
|
||||||
rateLimiter: deps.RateLimiter,
|
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) {
|
func (a *Amo) GetUserInfo(accessToken string, domain string) (*models.AmocrmUserInformation, error) {
|
||||||
for {
|
for {
|
||||||
if a.rateLimiter.Check() {
|
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 := a.fiberClient.Get(url)
|
||||||
agent.Set("Authorization", "Bearer "+accessToken)
|
agent.Set("Authorization", "Bearer "+accessToken)
|
||||||
statusCode, resBody, errs := agent.Bytes()
|
statusCode, resBody, errs := agent.Bytes()
|
||||||
@ -577,7 +574,7 @@ func (a *Amo) downloadFile(urlFile string) (*os.File, error) {
|
|||||||
return tmpFile, nil
|
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()
|
a.fileMutex.Lock()
|
||||||
defer a.fileMutex.Unlock()
|
defer a.fileMutex.Unlock()
|
||||||
localFile, err := a.downloadFile(urlFile)
|
localFile, err := a.downloadFile(urlFile)
|
||||||
@ -598,7 +595,7 @@ func (a *Amo) UploadFileToAmo(urlFile string, accessToken string) (*models.Value
|
|||||||
FileSize: fileSize,
|
FileSize: fileSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/v1.0/sessions", a.amoStorageURL)
|
uri := fmt.Sprintf("%s/v1.0/sessions", driveURL)
|
||||||
bodyBytes, err := json.Marshal(createSessionData)
|
bodyBytes, err := json.Marshal(createSessionData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.logger.Error("error marshal create session data:", zap.Error(err))
|
a.logger.Error("error marshal create session data:", zap.Error(err))
|
||||||
|
Loading…
Reference in New Issue
Block a user