🔥 Optimize 189 cloud get client
This commit is contained in:
parent
07d6ca27db
commit
e952f1c243
@ -36,6 +36,22 @@ import (
|
|||||||
|
|
||||||
var client189Map map[string]*resty.Client
|
var client189Map map[string]*resty.Client
|
||||||
|
|
||||||
|
func (driver Cloud189) getClient(account *model.Account) (*resty.Client, error) {
|
||||||
|
client, ok := client189Map[account.Name]
|
||||||
|
if ok {
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
err := driver.Login(account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
client, ok = client189Map[account.Name]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("can't find [%s] client", account.Name)
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
|
func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
|
||||||
f := &model.File{
|
f := &model.File{
|
||||||
Id: strconv.FormatInt(file.Id, 10),
|
Id: strconv.FormatInt(file.Id, 10),
|
||||||
@ -264,9 +280,9 @@ func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud1
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (driver Cloud189) Request(url string, method int, query, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
|
func (driver Cloud189) Request(url string, method int, query, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
|
||||||
client, ok := client189Map[account.Name]
|
client, err := driver.getClient(account)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't find [%s] client", account.Name)
|
return nil, err
|
||||||
}
|
}
|
||||||
//var resp base.Json
|
//var resp base.Json
|
||||||
if driver.isFamily(account) {
|
if driver.isFamily(account) {
|
||||||
@ -293,7 +309,6 @@ func (driver Cloud189) Request(url string, method int, query, form map[string]st
|
|||||||
if headers != nil {
|
if headers != nil {
|
||||||
req = req.SetHeaders(headers)
|
req = req.SetHeaders(headers)
|
||||||
}
|
}
|
||||||
var err error
|
|
||||||
var res *resty.Response
|
var res *resty.Response
|
||||||
switch method {
|
switch method {
|
||||||
case base.Get:
|
case base.Get:
|
||||||
|
@ -349,9 +349,9 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
if file == nil {
|
if file == nil {
|
||||||
return base.ErrEmptyFile
|
return base.ErrEmptyFile
|
||||||
}
|
}
|
||||||
client, ok := client189Map[account.Name]
|
client, err := driver.getClient(account)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return fmt.Errorf("can't find [%s] client", account.Name)
|
return err
|
||||||
}
|
}
|
||||||
parentFile, err := driver.File(file.ParentPath, account)
|
parentFile, err := driver.File(file.ParentPath, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user