-
Notifications
You must be signed in to change notification settings - Fork 2.1k
implement dropbox business teams #5708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this adds support for team spaces folders note: Do **not** enable any Team scopes (permissions) at https://www.dropbox.com/developers/apps that will break the app (making it a team admin app instead)
Diff output filesdiff --git a/packages/@uppy/companion/lib/server/provider/dropbox/index.js b/packages/@uppy/companion/lib/server/provider/dropbox/index.js
index 09b9de0..919063f 100644
--- a/packages/@uppy/companion/lib/server/provider/dropbox/index.js
+++ b/packages/@uppy/companion/lib/server/provider/dropbox/index.js
@@ -6,7 +6,8 @@ const adaptData = require("./adapter");
const { withProviderErrorHandling } = require("../providerErrors");
const { prepareStream } = require("../../helpers/utils");
const { MAX_AGE_REFRESH_TOKEN } = require("../../helpers/jwt");
-const got = require("../../got");
+const logger = require("../../logger");
+const gotPromise = require("../../got");
// From https://www.dropbox.com/developers/reference/json-encoding:
//
// This function is simple and has OK performance compared to more
@@ -17,19 +18,42 @@ function httpHeaderSafeJson(v) {
return `\\u${(`000${c.charCodeAt(0).toString(16)}`).slice(-4)}`;
});
}
-const getClient = async ({ token }) =>
- (await got).extend({
- prefixUrl: "https://api.dropboxapi.com/2",
- headers: {
- authorization: `Bearer ${token}`,
- },
- });
+async function getUserInfo({ client }) {
+ return client.post("users/get_current_account", { responseType: "json" }).json();
+}
+async function getClient({ token, namespaced }) {
+ const got = await gotPromise;
+ const makeClient = (namespace) =>
+ got.extend({
+ prefixUrl: "https://api.dropboxapi.com/2",
+ headers: {
+ authorization: `Bearer ${token}`,
+ ...(namespace ? { "Dropbox-API-Path-Root": JSON.stringify({ ".tag": "root", "root": namespace }) } : {}),
+ },
+ });
+ let client = makeClient();
+ const userInfo = await getUserInfo({ client });
+ // console.log('userInfo', userInfo)
+ // https://www.dropboxforum.com/discussions/101000014/how-to-list-the-contents-of-a-team-folder/258310
+ // https://developers.dropbox.com/dbx-team-files-guide#namespaces
+ // https://www.dropbox.com/developers/reference/path-root-header-modes
+ if (
+ namespaced && userInfo.root_info != null
+ && userInfo.root_info.root_namespace_id !== userInfo.root_info.home_namespace_id
+ ) {
+ logger.debug("using root_namespace_id", userInfo.root_info.root_namespace_id);
+ client = makeClient(userInfo.root_info.root_namespace_id);
+ }
+ return {
+ client,
+ userInfo,
+ };
+}
const getOauthClient = async () =>
- (await got).extend({
+ (await gotPromise).extend({
prefixUrl: "https://api.dropboxapi.com/oauth2",
});
-async function list({ directory, query, token }) {
- const client = await getClient({ token });
+async function list({ client, directory, query }) {
if (query.cursor) {
return client.post("files/list_folder/continue", { json: { cursor: query.cursor }, responseType: "json" }).json();
}
@@ -44,9 +68,6 @@ async function list({ directory, query, token }) {
responseType: "json",
}).json();
}
-async function userInfo({ token }) {
- return (await getClient({ token })).post("users/get_current_account", { responseType: "json" }).json();
-}
/**
* Adapter for API https://www.dropbox.com/developers/documentation/http/documentation
*/
@@ -66,18 +87,15 @@ class DropBox extends Provider {
*/
async list(options) {
return this.#withErrorHandling("provider.dropbox.list.error", async () => {
- const responses = await Promise.all([
- list(options),
- userInfo(options),
- ]);
- // @ts-ignore
- const [stats, { email }] = responses;
+ const { client, userInfo } = await getClient({ token: options.token, namespaced: true });
+ const stats = await list({ ...options, client });
+ const { email } = userInfo;
return adaptData(stats, email, options.companion.buildURL);
});
}
async download({ id, token }) {
return this.#withErrorHandling("provider.dropbox.download.error", async () => {
- const stream = (await getClient({ token })).stream.post("files/download", {
+ const stream = (await getClient({ token, namespaced: true })).client.stream.post("files/download", {
prefixUrl: "https://content.dropboxapi.com/2",
headers: {
"Dropbox-API-Arg": httpHeaderSafeJson({ path: String(id) }),
@@ -92,7 +110,7 @@ class DropBox extends Provider {
}
async thumbnail({ id, token }) {
return this.#withErrorHandling("provider.dropbox.thumbnail.error", async () => {
- const stream = (await getClient({ token })).stream.post("files/get_thumbnail_v2", {
+ const stream = (await getClient({ token, namespaced: true })).client.stream.post("files/get_thumbnail_v2", {
prefixUrl: "https://content.dropboxapi.com/2",
headers: {
"Dropbox-API-Arg": httpHeaderSafeJson({
@@ -110,7 +128,7 @@ class DropBox extends Provider {
}
async size({ id, token }) {
return this.#withErrorHandling("provider.dropbox.size.error", async () => {
- const { size } = await (await getClient({ token })).post("files/get_metadata", {
+ const { size } = await (await getClient({ token, namespaced: true })).client.post("files/get_metadata", {
json: { path: id },
responseType: "json",
}).json();
@@ -119,7 +137,7 @@ class DropBox extends Provider {
}
async logout({ token }) {
return this.#withErrorHandling("provider.dropbox.logout.error", async () => {
- await (await getClient({ token })).post("auth/token/revoke", { responseType: "json" });
+ await (await getClient({ token, namespaced: false })).client.post("auth/token/revoke", { responseType: "json" });
return { revoked: true };
});
} |
Murderlon
approved these changes
Apr 7, 2025
Merged
github-actions bot
added a commit
that referenced
this pull request
Apr 8, 2025
| Package | Version | Package | Version | | -------------------------- | ------- | -------------------------- | ------- | | @uppy/audio | 2.1.2 | @uppy/locales | 4.5.2 | | @uppy/box | 3.2.2 | @uppy/onedrive | 4.2.3 | | @uppy/companion | 5.6.0 | @uppy/react | 4.2.3 | | @uppy/core | 4.4.4 | @uppy/remote-sources | 2.3.2 | | @uppy/dashboard | 4.3.3 | @uppy/screen-capture | 4.2.2 | | @uppy/drag-drop | 4.1.2 | @uppy/status-bar | 4.1.3 | | @uppy/dropbox | 4.2.2 | @uppy/transloadit | 4.2.2 | | @uppy/facebook | 4.2.2 | @uppy/unsplash | 4.3.3 | | @uppy/file-input | 4.1.2 | @uppy/url | 4.2.3 | | @uppy/google-drive | 4.3.2 | @uppy/utils | 6.1.3 | | @uppy/google-drive-picker | 0.3.4 | @uppy/webcam | 4.1.2 | | @uppy/google-photos-picker | 0.3.4 | @uppy/webdav | 0.3.2 | | @uppy/image-editor | 3.3.2 | @uppy/zoom | 3.2.2 | | @uppy/instagram | 4.2.2 | uppy | 4.14.0 | - @uppy/core: dry retryAll() and upload() (Mikael Finstad / #5691) - @uppy/angular: Revert "Support Angular 19" (Mikael Finstad / #5710) - @uppy/angular: Support Angular 19 (Arnaud Flaesch / #5709) - @uppy/companion: implement dropbox business teams (Mikael Finstad / #5708) - @uppy/utils: add msg mimetype (Merlijn Vos / #5699) - @uppy/core: fix locale type for plugins (Merlijn Vos / #5700) - examples: build(deps-dev): bump vite from 5.4.14 to 5.4.15 (dependabot[bot] / #5703) - @uppy/locales: Update nb_NO.ts (Tore Sinding Bekkedal / #5678) - meta: build(deps): bump docker/login-action from 3.3.0 to 3.4.0 (dependabot[bot] / #5689) - examples: @uppy-example/aws-nodejs: fix fileType not present in S3 objects (Prakash / #5680) - @uppy/core: fix events when retrying with upload() (Prakash / #5696) - meta: Fix locales building (Mikael Finstad / #5693) - @uppy/google-photos: remove google photos 😢 (Mikael Finstad / #5690) - @uppy/locales: Update cs_CZ.ts (David Petrásek / #5658)
Murderlon
added a commit
8827
that referenced
this pull request
Apr 15, 2025
* main: Fix google photos picker (#5717) build(deps): bump nanoid from 3.3.7 to 5.1.2 (#5664) build(deps-dev): bump vite from 5.4.16 to 5.4.17 (#5707) Fix type check ci (#5714) Support Angular 19 (#5709) (#5715) simplify e2e (#5711) fix ready to commit (#5713) Release: uppy@4.14.0 (#5712) dry retryAll() and upload() (#5691) Revert "Support Angular 19" (#5710) Support Angular 19 (#5709) implement dropbox business teams (#5708)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this adds support for team spaces folders
note: Do not enable any Team scopes (permissions) at https://www.dropbox.com/developers/apps that will break the app (making it a team admin app instead)