mirror of https://github.com/Xhofe/alist
fix(seafile): token refresh (#3010)
* docs: add Seafile support * fix: Seafile token refreshpull/3055/head
parent
2dc5dec83c
commit
aaa8c440fe
|
@ -53,6 +53,7 @@
|
||||||
- [x] FTP / SFTP
|
- [x] FTP / SFTP
|
||||||
- [x] [PikPak](https://www.mypikpak.com/)
|
- [x] [PikPak](https://www.mypikpak.com/)
|
||||||
- [x] [S3](https://aws.amazon.com/cn/s3/)
|
- [x] [S3](https://aws.amazon.com/cn/s3/)
|
||||||
|
- [x] [Seafile](https://seafile.com/)
|
||||||
- [x] [又拍云对象存储](https://www.upyun.com/products/file-storage)
|
- [x] [又拍云对象存储](https://www.upyun.com/products/file-storage)
|
||||||
- [x] WebDav(支持无API的OneDrive/SharePoint)
|
- [x] WebDav(支持无API的OneDrive/SharePoint)
|
||||||
- [x] Teambition([中国](https://www.teambition.com/ ),[国际](https://us.teambition.com/ ))
|
- [x] Teambition([中国](https://www.teambition.com/ ),[国际](https://us.teambition.com/ ))
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *Seafile) getToken() error {
|
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] {
|
if len(noRedirect) > 0 && noRedirect[0] {
|
||||||
req = base.NoRedirectClient.R()
|
req = base.NoRedirectClient.R()
|
||||||
}
|
}
|
||||||
req.SetHeader("Authorization", d.authorization)
|
var res resty.Response
|
||||||
callback(req)
|
for i := 0; i < 2; i++ {
|
||||||
res, err := req.Execute(method, full)
|
req.SetHeader("Authorization", d.authorization)
|
||||||
if err != nil {
|
callback(req)
|
||||||
return nil, err
|
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 {
|
if res.StatusCode() >= 400 {
|
||||||
return nil, fmt.Errorf("request failed: %s", res.String())
|
return nil, fmt.Errorf("request failed: %s", res.String())
|
||||||
|
|
Loading…
Reference in New Issue