Skip to content

Commit

Permalink
feat(dropbox): add root_namespace_id to access teams folder
Browse files Browse the repository at this point in the history
  • Loading branch information
shouko committed Jan 21, 2024
1 parent d88b54d commit 367e9b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion drivers/dropbox/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ func (d *Dropbox) Init(ctx context.Context) error {
if result != query {
return fmt.Errorf("failed to check user: %s", string(res))
}
return nil
d.RootNamespaceId, err = d.GetRootNamespaceId(ctx)

return err
}

func (d *Dropbox) GetRootNamespaceId(ctx context.Context) (string, error) {
res, err := d.request("/2/users/get_current_account", http.MethodPost, func(req *resty.Request) {
req.SetContext(ctx)
})
if err != nil {
return "", err
}
rootNamespaceID := utils.Json.Get(res, "root_info.root_namespace_id").ToString()
return rootNamespaceID, nil
}

func (d *Dropbox) Drop(ctx context.Context) error {
Expand Down
1 change: 1 addition & 0 deletions drivers/dropbox/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Addition struct {
ClientSecret string `json:"client_secret" required:"false" help:"Keep it empty if you don't have one"`

AccessToken string
RootNamespaceId string
}

var config = driver.Config{
Expand Down
10 changes: 10 additions & 0 deletions drivers/dropbox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ func (d *Dropbox) refreshToken() error {
func (d *Dropbox) request(uri, method string, callback base.ReqCallback, retry ...bool) ([]byte, error) {
req := base.RestyClient.R()
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
if d.RootNamespaceId != "" {
apiPathRootJson, err := utils.Json.MarshalToString(map[string]interface{}{
".tag": "root",
"root": d.RootNamespaceId,
})
if err != nil {
return nil, err
}
req.SetHeader("Dropbox-API-Path-Root", apiPathRootJson)
}
if method == http.MethodPost {
req.SetHeader("Content-Type", "application/json")
}
Expand Down

0 comments on commit 367e9b2

Please sign in to comment.