Skip to content

Commit a109152

Browse files
jerritaj2rong4cn
andauthored
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>
1 parent febbcd6 commit a109152

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/onedrive/driver.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Onedrive struct {
2222
AccessToken string
2323
root *Object
2424
mutex sync.Mutex
25+
ref *Onedrive
2526
}
2627

2728
func (d *Onedrive) Config() driver.Config {
@@ -36,10 +37,22 @@ func (d *Onedrive) Init(ctx context.Context) error {
3637
if d.ChunkSize < 1 {
3738
d.ChunkSize = 5
3839
}
40+
if d.ref != nil {
41+
return nil
42+
}
3943
return d.refreshToken()
4044
}
4145

46+
func (d *Onedrive) InitReference(refStorage driver.Driver) error {
47+
if ref, ok := refStorage.(*Onedrive); ok {
48+
d.ref = ref
49+
return nil
50+
}
51+
return errs.NotSupport
52+
}
53+
4254
func (d *Onedrive) Drop(ctx context.Context) error {
55+
d.ref = nil
4356
return nil
4457
}
4558

drivers/onedrive/util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func (d *Onedrive) _refreshToken() error {
134134
}
135135

136136
func (d *Onedrive) Request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
137+
if d.ref != nil {
138+
return d.ref.Request(url, method, callback, resp)
139+
}
137140
req := base.RestyClient.R()
138141
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
139142
if callback != nil {

0 commit comments

Comments
 (0)