🐛 fix onedrive get files

This commit is contained in:
微凉 2021-11-23 15:39:09 +08:00
parent b1695445e0
commit 5500980d63

View File

@ -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,
},
} }
} }
@ -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) {