mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 03:15:19 +08:00
feat(onedrive): add ref support (#1435)
* feat(onedrive): add ref support * fix(onedrive): remove redundant token assignment from reference --------- Co-authored-by: j2rong4cn <j2rong@qq.com>
This commit is contained in:
@@ -22,6 +22,7 @@ type Onedrive struct {
|
||||
AccessToken string
|
||||
root *Object
|
||||
mutex sync.Mutex
|
||||
ref *Onedrive
|
||||
}
|
||||
|
||||
func (d *Onedrive) Config() driver.Config {
|
||||
@@ -36,10 +37,22 @@ func (d *Onedrive) Init(ctx context.Context) error {
|
||||
if d.ChunkSize < 1 {
|
||||
d.ChunkSize = 5
|
||||
}
|
||||
if d.ref != nil {
|
||||
return nil
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
|
||||
func (d *Onedrive) InitReference(refStorage driver.Driver) error {
|
||||
if ref, ok := refStorage.(*Onedrive); ok {
|
||||
d.ref = ref
|
||||
return nil
|
||||
}
|
||||
return errs.NotSupport
|
||||
}
|
||||
|
||||
func (d *Onedrive) Drop(ctx context.Context) error {
|
||||
d.ref = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,9 @@ func (d *Onedrive) _refreshToken() error {
|
||||
}
|
||||
|
||||
func (d *Onedrive) Request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
if d.ref != nil {
|
||||
return d.ref.Request(url, method, callback, resp)
|
||||
}
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
|
||||
if callback != nil {
|
||||
|
||||
Reference in New Issue
Block a user