Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions drivers/onedrive/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Onedrive struct {
AccessToken string
root *Object
mutex sync.Mutex
ref *Onedrive
}

func (d *Onedrive) Config() driver.Config {
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions drivers/onedrive/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down