fix(seafile): token refresh (#3010)

* docs: add Seafile support

* fix: Seafile token refresh
pull/3055/head
Zexi 2023-01-13 21:20:21 +08:00 committed by GitHub
parent 2dc5dec83c
commit aaa8c440fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -53,6 +53,7 @@
- [x] FTP / SFTP
- [x] [PikPak](https://www.mypikpak.com/)
- [x] [S3](https://aws.amazon.com/cn/s3/)
- [x] [Seafile](https://seafile.com/)
- [x] [又拍云对象存储](https://www.upyun.com/products/file-storage)
- [x] WebDav(支持无API的OneDrive/SharePoint)
- [x] Teambition[中国](https://www.teambition.com/ )[国际](https://us.teambition.com/ )

View File

@ -5,6 +5,7 @@ import (
"strings"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/go-resty/resty/v2"
)
func (d *Seafile) getToken() error {
@ -35,11 +36,21 @@ func (d *Seafile) request(method string, pathname string, callback base.ReqCallb
if len(noRedirect) > 0 && noRedirect[0] {
req = base.NoRedirectClient.R()
}
req.SetHeader("Authorization", d.authorization)
callback(req)
res, err := req.Execute(method, full)
if err != nil {
return nil, err
var res resty.Response
for i := 0; i < 2; i++ {
req.SetHeader("Authorization", d.authorization)
callback(req)
res, err := req.Execute(method, full)
if err != nil {
return nil, err
}
if res.StatusCode() != 401 { // Unauthorized
break
}
err = d.getToken()
if err != nil {
return nil, err
}
}
if res.StatusCode() >= 400 {
return nil, fmt.Errorf("request failed: %s", res.String())