From 517abe58f4c3c676fa4212770acec75ce803d20a Mon Sep 17 00:00:00 2001 From: ifedapoolarewaju Date: Mon, 23 Sep 2019 15:01:52 +0100 Subject: [PATCH 1/4] companion,google-drive: drop deprecated usage for Google Drive's "shared drive" feature --- .../src/server/provider/drive/adapter.js | 6 ++-- .../src/server/provider/drive/index.js | 33 ++++++++++--------- .../google-drive/src/DriveProviderViews.js | 6 ++-- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/@uppy/companion/src/server/provider/drive/adapter.js b/packages/@uppy/companion/src/server/provider/drive/adapter.js index 5cec1ef186..a830cde97b 100644 --- a/packages/@uppy/companion/src/server/provider/drive/adapter.js +++ b/packages/@uppy/companion/src/server/provider/drive/adapter.js @@ -13,7 +13,7 @@ exports.getUsername = (data) => { } exports.isFolder = (item) => { - return item.mimeType === 'application/vnd.google-apps.folder' || item.kind === 'drive#teamDrive' + return item.mimeType === 'application/vnd.google-apps.folder' || exports.isSharedDrive(item) } exports.getItemSize = (item) => { @@ -67,8 +67,8 @@ exports.getItemThumbnailUrl = (item) => { return `/drive/thumbnail/${exports.getItemRequestPath(item)}` } -exports.isTeamDrive = (item) => { - return item.kind === 'drive#teamDrive' +exports.isSharedDrive = (item) => { + return item.kind === 'drive#drive' } exports.getNextPagePath = (data, currentQuery, currentPath) => { diff --git a/packages/@uppy/companion/src/server/provider/drive/index.js b/packages/@uppy/companion/src/server/provider/drive/index.js index 19c1c7a696..be0ce06f07 100644 --- a/packages/@uppy/companion/src/server/provider/drive/index.js +++ b/packages/@uppy/companion/src/server/provider/drive/index.js @@ -6,7 +6,7 @@ const adapter = require('./adapter') const AuthError = require('../error') const DRIVE_FILE_FIELDS = 'kind,id,name,mimeType,ownedByMe,permissions(role,emailAddress),size,modifiedTime,iconLink,thumbnailLink,teamDriveId' const DRIVE_FILES_FIELDS = `kind,nextPageToken,incompleteSearch,files(${DRIVE_FILE_FIELDS})` -const TEAM_DRIVE_FIELDS = 'teamDrives(kind,id,name,backgroundImageLink)' +const SHARED_DRIVE_FIELDS = 'drives(kind,id,name,backgroundImageLink)' class Drive { constructor (options) { @@ -25,19 +25,19 @@ class Drive { const directory = options.directory || 'root' const query = options.query || {} - let teamDrivesPromise = Promise.resolve(undefined) + let sharedDrivesPromise = Promise.resolve(undefined) - const shouldListTeamDrives = directory === 'root' && !query.cursor - if (shouldListTeamDrives) { - teamDrivesPromise = new Promise((resolve) => { + const shouldListSharedDrives = directory === 'root' && !query.cursor + if (shouldListSharedDrives) { + sharedDrivesPromise = new Promise((resolve) => { this.client .query() - .get('teamdrives') - .qs({ fields: TEAM_DRIVE_FIELDS }) + .get('drives') + .qs({ fields: SHARED_DRIVE_FIELDS }) .auth(options.token) .request((err, resp) => { if (err) { - logger.error(err, 'provider.drive.teamDrive.error') + logger.error(err, 'provider.drive.sharedDrive.error') return } resolve(resp) @@ -68,7 +68,7 @@ class Drive { }) }) - Promise.all([teamDrivesPromise, filesPromise]) + Promise.all([sharedDrivesPromise, filesPromise]) .then( ([teamDrives, filesResponse]) => { const returnData = this.adaptData( @@ -91,7 +91,7 @@ class Drive { return this.client .query() .get(`files/${id}`) - .qs({ fields: DRIVE_FILE_FIELDS, supportsTeamDrives: true }) + .qs({ fields: DRIVE_FILE_FIELDS, supportsAllDrives: true }) .auth(token) .request(done) } @@ -100,7 +100,7 @@ class Drive { return this.client .query() .get(`files/${id}`) - .qs({ alt: 'media', supportsTeamDrives: true }) + .qs({ alt: 'media', supportsAllDrives: true }) .auth(token) .request() .on('data', onData) @@ -133,7 +133,7 @@ class Drive { }) } - adaptData (res, teamDrivesResp, uppy, directory, query) { + adaptData (res, sharedDrivesResp, uppy, directory, query) { const adaptItem = (item) => ({ isFolder: adapter.isFolder(item), icon: adapter.getItemIcon(item), @@ -145,14 +145,17 @@ class Drive { modifiedDate: adapter.getItemModifiedDate(item), size: adapter.getItemSize(item), custom: { - isTeamDrive: adapter.isTeamDrive(item) + // @todo isTeamDrive is left for backward compatibility. We should remove it in the next + // major release. + isTeamDrive: adapter.isSharedDrive(item), + isSharedDrive: adapter.isSharedDrive(item) } }) const items = adapter.getItemSubList(res) - const teamDrives = teamDrivesResp ? teamDrivesResp.teamDrives || [] : [] + const sharedDrives = sharedDrivesResp ? sharedDrivesResp.drives || [] : [] - const adaptedItems = teamDrives.concat(items).map(adaptItem) + const adaptedItems = sharedDrives.concat(items).map(adaptItem) return { username: adapter.getUsername(res), diff --git a/packages/@uppy/google-drive/src/DriveProviderViews.js b/packages/@uppy/google-drive/src/DriveProviderViews.js index bffffeeadd..2bc6c204db 100644 --- a/packages/@uppy/google-drive/src/DriveProviderViews.js +++ b/packages/@uppy/google-drive/src/DriveProviderViews.js @@ -5,8 +5,10 @@ module.exports = class DriveProviderViews extends ProviderViews { e.stopPropagation() e.preventDefault() - // Team Drives aren't selectable; for all else, defer to the base ProviderView. - if (!file.custom.isTeamDrive) { + // Shared Drives aren't selectable; for all else, defer to the base ProviderView. + // @todo isTeamDrive is left for backward compatibility. We should remove it in the next + // major release. + if (!file.custom.isTeamDrive && !file.custom.isSharedDrive) { super.toggleCheckbox(e, file) } } From ca6adbb0dc67b9b5d3b33bebf32037a6703c2984 Mon Sep 17 00:00:00 2001 From: ifedapoolarewaju Date: Mon, 23 Sep 2019 20:14:15 +0100 Subject: [PATCH 2/4] companion: fix shared drive icon --- packages/@uppy/companion/src/server/provider/drive/adapter.js | 2 +- packages/@uppy/companion/src/server/provider/drive/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@uppy/companion/src/server/provider/drive/adapter.js b/packages/@uppy/companion/src/server/provider/drive/adapter.js index a830cde97b..4187292d17 100644 --- a/packages/@uppy/companion/src/server/provider/drive/adapter.js +++ b/packages/@uppy/companion/src/server/provider/drive/adapter.js @@ -21,7 +21,7 @@ exports.getItemSize = (item) => { } exports.getItemIcon = (item) => { - if (item.kind === 'drive#teamDrive') { + if (exports.isSharedDrive(item)) { const size = '=w16-h16-n' const sizeParamRegex = /=[-whncsp0-9]*$/ return item.backgroundImageLink.match(sizeParamRegex) diff --git a/packages/@uppy/companion/src/server/provider/drive/index.js b/packages/@uppy/companion/src/server/provider/drive/index.js index be0ce06f07..735268c174 100644 --- a/packages/@uppy/companion/src/server/provider/drive/index.js +++ b/packages/@uppy/companion/src/server/provider/drive/index.js @@ -70,10 +70,10 @@ class Drive { Promise.all([sharedDrivesPromise, filesPromise]) .then( - ([teamDrives, filesResponse]) => { + ([sharedDrives, filesResponse]) => { const returnData = this.adaptData( filesResponse.body, - teamDrives && teamDrives.body, + sharedDrives && sharedDrives.body, options.uppy, directory, query From 5dd4aaf71dfef5007a8587629342893aa73fcbd9 Mon Sep 17 00:00:00 2001 From: ifedapoolarewaju Date: Wed, 25 Sep 2019 15:05:18 +0100 Subject: [PATCH 3/4] debug,companion: add other fields for testing --- packages/@uppy/companion/src/server/provider/drive/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/companion/src/server/provider/drive/index.js b/packages/@uppy/companion/src/server/provider/drive/index.js index 735268c174..6a0d7080dd 100644 --- a/packages/@uppy/companion/src/server/provider/drive/index.js +++ b/packages/@uppy/companion/src/server/provider/drive/index.js @@ -6,7 +6,7 @@ const adapter = require('./adapter') const AuthError = require('../error') const DRIVE_FILE_FIELDS = 'kind,id,name,mimeType,ownedByMe,permissions(role,emailAddress),size,modifiedTime,iconLink,thumbnailLink,teamDriveId' const DRIVE_FILES_FIELDS = `kind,nextPageToken,incompleteSearch,files(${DRIVE_FILE_FIELDS})` -const SHARED_DRIVE_FIELDS = 'drives(kind,id,name,backgroundImageLink)' +const SHARED_DRIVE_FIELDS = 'drives(kind,id,name,backgroundImageLink,hidden)' class Drive { constructor (options) { From f366f4f5abe1547c3503063594754d5a396eac7b Mon Sep 17 00:00:00 2001 From: ifedapoolarewaju Date: Wed, 25 Sep 2019 15:36:51 +0100 Subject: [PATCH 4/4] companion: allow all fields for GDrive's "/drives" endpoint --- packages/@uppy/companion/src/server/provider/drive/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/companion/src/server/provider/drive/index.js b/packages/@uppy/companion/src/server/provider/drive/index.js index 6a0d7080dd..f726c8bd0b 100644 --- a/packages/@uppy/companion/src/server/provider/drive/index.js +++ b/packages/@uppy/companion/src/server/provider/drive/index.js @@ -6,7 +6,8 @@ const adapter = require('./adapter') const AuthError = require('../error') const DRIVE_FILE_FIELDS = 'kind,id,name,mimeType,ownedByMe,permissions(role,emailAddress),size,modifiedTime,iconLink,thumbnailLink,teamDriveId' const DRIVE_FILES_FIELDS = `kind,nextPageToken,incompleteSearch,files(${DRIVE_FILE_FIELDS})` -const SHARED_DRIVE_FIELDS = 'drives(kind,id,name,backgroundImageLink,hidden)' +// using wildcard to get all 'drive' fields because specifying fields seems no to work for the /drives endpoint +const SHARED_DRIVE_FIELDS = '*' class Drive { constructor (options) {