🐛 fix onedrive get files
This commit is contained in:
parent
b1695445e0
commit
5500980d63
@ -135,6 +135,20 @@ func (o Onedrive) Items() []Item {
|
|||||||
Type: "string",
|
Type: "string",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "order_by",
|
||||||
|
Label: "order_by",
|
||||||
|
Type: "select",
|
||||||
|
Values: "name,size,lastModifiedDateTime",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "order_direction",
|
||||||
|
Label: "order_direction",
|
||||||
|
Type: "select",
|
||||||
|
Values: "asc,desc",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +175,7 @@ func (o Onedrive) RefreshToken(account *model.Account) error {
|
|||||||
if e.Error != "" {
|
if e.Error != "" {
|
||||||
account.Status = e.ErrorDescription
|
account.Status = e.ErrorDescription
|
||||||
return fmt.Errorf("%s", e.ErrorDescription)
|
return fmt.Errorf("%s", e.ErrorDescription)
|
||||||
}else {
|
} else {
|
||||||
account.Status = "work"
|
account.Status = "work"
|
||||||
}
|
}
|
||||||
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
|
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||||
@ -180,6 +194,7 @@ type OneFile struct {
|
|||||||
|
|
||||||
type OneFiles struct {
|
type OneFiles struct {
|
||||||
Value []OneFile `json:"value"`
|
Value []OneFile `json:"value"`
|
||||||
|
NextLink string `json:"@odata.nextLink"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OneRespErr struct {
|
type OneRespErr struct {
|
||||||
@ -206,18 +221,30 @@ func (o Onedrive) FormatFile(file *OneFile) *model.File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o Onedrive) GetFiles(account *model.Account, path string) ([]OneFile, error) {
|
func (o Onedrive) GetFiles(account *model.Account, path string) ([]OneFile, error) {
|
||||||
|
var res []OneFile
|
||||||
|
nextLink := o.GetMetaUrl(account, false, path) + "/children"
|
||||||
|
if account.OrderBy != "" {
|
||||||
|
nextLink += fmt.Sprintf("?orderby=%s", account.OrderBy)
|
||||||
|
if account.OrderDirection != "" {
|
||||||
|
nextLink += fmt.Sprintf(" %s", account.OrderDirection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for nextLink != "" {
|
||||||
var files OneFiles
|
var files OneFiles
|
||||||
var e OneRespErr
|
var e OneRespErr
|
||||||
_, err := oneClient.R().SetResult(&files).SetError(&e).
|
_, err := oneClient.R().SetResult(&files).SetError(&e).
|
||||||
SetHeader("Authorization", "Bearer "+account.AccessToken).
|
SetHeader("Authorization", "Bearer "+account.AccessToken).
|
||||||
Get(o.GetMetaUrl(account, false, path) + "/children")
|
Get(nextLink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if e.Error.Code != "" {
|
if e.Error.Code != "" {
|
||||||
return nil, fmt.Errorf("%s", e.Error.Message)
|
return nil, fmt.Errorf("%s", e.Error.Message)
|
||||||
}
|
}
|
||||||
return files.Value, nil
|
res = append(res, files.Value...)
|
||||||
|
nextLink = files.NextLink
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Onedrive) GetFile(account *model.Account, path string) (*OneFile, error) {
|
func (o Onedrive) GetFile(account *model.Account, path string) (*OneFile, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user