Add support for Dropbox team folders with path-root header#217
Add support for Dropbox team folders with path-root header#217neon-ninja wants to merge 5 commits intodropbox:masterfrom
Conversation
…der support Co-authored-by: neon-ninja <3378822+neon-ninja@users.noreply.github.com>
…path-root flag Co-authored-by: neon-ninja <3378822+neon-ninja@users.noreply.github.com>
… on root path Co-authored-by: neon-ninja <3378822+neon-ninja@users.noreply.github.com>
…-root-header Auto-detect root namespace to support Dropbox team folders via Dropbox-API-Path-Root header
|
|
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI’s Dropbox client initialization to automatically set the Dropbox-API-Path-Root header (so Dropbox Business team folders are accessible by default), and adjusts ls to better distinguish file vs folder paths (especially for root).
Changes:
- Auto-detect root namespace via
users.GetCurrentAccountand setDropbox-API-Path-Rootfor non-teamManagetokens. - Update
lsto avoid callingget_metadatafor the root path and to short-circuit when the target is a file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| cmd/root.go | Adds root-namespace auto-detection and configures Dropbox-API-Path-Root header generation. |
| cmd/ls.go | Improves file-vs-folder detection (and avoids root-path get_metadata errors). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| printItem(formatFileMetadata(f, long)) | ||
| err = w.Flush() | ||
| return err | ||
| } |
| usersClient := users.New(config) | ||
| account, accountErr := usersClient.GetCurrentAccount() | ||
| if accountErr != nil { | ||
| config.LogInfo("Warning: could not auto-detect root namespace (%v); team folders may not be accessible", accountErr) |
| pathRootHeader := fmt.Sprintf(`{".tag": "root", "root": "%s"}`, rootNamespaceID) | ||
| config.HeaderGenerator = func(_, _, _, _ string) map[string]string { | ||
| return map[string]string{"Dropbox-API-Path-Root": pathRootHeader} | ||
| } |
| usersClient := users.New(config) | ||
| account, accountErr := usersClient.GetCurrentAccount() | ||
| if accountErr != nil { | ||
| config.LogInfo("Warning: could not auto-detect root namespace (%v); team folders may not be accessible", accountErr) | ||
| } else { | ||
| var rootNamespaceID string | ||
| switch ri := account.RootInfo.(type) { | ||
| case *common.TeamRootInfo: | ||
| rootNamespaceID = ri.RootNamespaceId | ||
| case *common.UserRootInfo: | ||
| rootNamespaceID = ri.RootNamespaceId | ||
| } | ||
| if rootNamespaceID != "" { | ||
| pathRootHeader := fmt.Sprintf(`{".tag": "root", "root": "%s"}`, rootNamespaceID) | ||
| config.HeaderGenerator = func(_, _, _, _ string) map[string]string { | ||
| return map[string]string{"Dropbox-API-Path-Root": pathRootHeader} | ||
| } | ||
| } | ||
| } |
This pull request improves the handling of Dropbox root namespaces to ensure team folders are accessible and enhances the
lscommand's behavior for file and folder detection. The most important changes are grouped below:Dropbox root namespace auto-detection:
initDbx(incmd/root.go) to automatically detect and set the Dropbox root namespace header for non-admin tokens, making team folders accessible by default. This involves callingusers.GetCurrentAccountand setting theDropbox-API-Path-Rootheader based on the user's or team's root namespace.usersandcommonpackages to support root namespace detection.Enhancements to the
lscommand:lscommand incmd/ls.goto check if the provided path exists and is a file (except for the root path), improving error handling and output formatting for file listings. [1] [2]General improvements: