8000 implement dropbox business teams by mifi · Pull Request #5708 · transloadit/uppy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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 3 commits into from
Apr 7, 2025
Merged

implement dropbox business teams #5708

merged 3 commits into from
Apr 7, 2025

Conversation

mifi
Copy link
Contributor
@mifi mifi commented Apr 4, 2025

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)

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)
Copy link
Contributor
github-actions bot commented Apr 4, 2025
Diff output files
diff --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 };
     });
   }

@mifi mifi merged commit b339ae0 into main Apr 7, 2025
19 checks passed
@mifi mifi deleted the dropbox-business branch April 7, 2025 13:06
@github-actions github-actions bot mentioned this pull request Apr 8, 2025
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0