|
@@ -1,6 +1,6 @@
|
|
const { Plugin } = require('@uppy/core')
|
|
const { Plugin } = require('@uppy/core')
|
|
const { Provider } = require('@uppy/companion-client')
|
|
const { Provider } = require('@uppy/companion-client')
|
|
-const ProviderViews = require('@uppy/provider-views')
|
|
|
|
|
|
+const DriveProviderViews = require('./DriveProviderViews')
|
|
const { h } = require('preact')
|
|
const { h } = require('preact')
|
|
|
|
|
|
module.exports = class GoogleDrive extends Plugin {
|
|
module.exports = class GoogleDrive extends Plugin {
|
|
@@ -32,7 +32,7 @@ module.exports = class GoogleDrive extends Plugin {
|
|
}
|
|
}
|
|
|
|
|
|
install () {
|
|
install () {
|
|
- this.view = new ProviderViews(this)
|
|
|
|
|
|
+ this.view = new DriveProviderViews(this)
|
|
// Set default state for Google Drive
|
|
// Set default state for Google Drive
|
|
this.setPluginState({
|
|
this.setPluginState({
|
|
authenticated: false,
|
|
authenticated: false,
|
|
@@ -41,7 +41,10 @@ module.exports = class GoogleDrive extends Plugin {
|
|
directories: [],
|
|
directories: [],
|
|
activeRow: -1,
|
|
activeRow: -1,
|
|
filterInput: '',
|
|
filterInput: '',
|
|
- isSearchVisible: false
|
|
|
|
|
|
+ isSearchVisible: false,
|
|
|
|
+ hasTeamDrives: false,
|
|
|
|
+ teamDrives: [],
|
|
|
|
+ teamDriveId: ''
|
|
})
|
|
})
|
|
|
|
|
|
const target = this.opts.target
|
|
const target = this.opts.target
|
|
@@ -59,9 +62,19 @@ module.exports = class GoogleDrive extends Plugin {
|
|
this.setPluginState({ authenticated })
|
|
this.setPluginState({ authenticated })
|
|
if (authenticated) {
|
|
if (authenticated) {
|
|
this.view.getFolder('root')
|
|
this.view.getFolder('root')
|
|
|
|
+ this.getTeamDrives()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getTeamDrives () {
|
|
|
|
+ this[this.id].get(`${this.GoogleDrive.id}/list/?listTeamDrives=true`)
|
|
|
|
+ .then((payload) => {
|
|
|
|
+ if (payload.teamDrives && payload.teamDrives.length) {
|
|
|
|
+ this.setPluginState({hasTeamDrives: true, teamDrives: payload.teamDrives})
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
getUsername (data) {
|
|
getUsername (data) {
|
|
for (const item of data.files) {
|
|
for (const item of data.files) {
|
|
if (item.ownedByMe) {
|
|
if (item.ownedByMe) {
|
|
@@ -105,6 +118,13 @@ module.exports = class GoogleDrive extends Plugin {
|
|
}
|
|
}
|
|
|
|
|
|
getItemRequestPath (item) {
|
|
getItemRequestPath (item) {
|
|
|
|
+ // If it's from a Team Drive, add the Team Drive ID as a query param.
|
|
|
|
+ // The server needs the Team Drive ID to list files in a Team Drive folder.
|
|
|
|
+ if (item.teamDriveId) {
|
|
|
|
+ item.id += `?teamDriveId=${item.teamDriveId}`
|
|
|
|
+ delete item.teamDriveId
|
|
|
|
+ }
|
|
|
|
+
|
|
return this.getItemId(item)
|
|
return this.getItemId(item)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,6 +137,34 @@ module.exports = class GoogleDrive extends Plugin {
|
|
}
|
|
}
|
|
|
|
|
|
render (state) {
|
|
render (state) {
|
|
|
|
+ let pluginState = this.getPluginState()
|
|
|
|
+
|
|
|
|
+ // If the user has access to any Team Drives, handle them as needed.
|
|
|
|
+ if (pluginState.hasTeamDrives) {
|
|
|
|
+ let folders = pluginState.folders
|
|
|
|
+
|
|
|
|
+ // Remove any Team Drives we've previously pushed into the list of folders.
|
|
|
|
+ folders = folders.filter((folder) => {
|
|
|
|
+ return folder.kind !== 'drive#teamDrive'
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ // If viewing the Google Drive root, add Team Drives to the top of the list.
|
|
|
|
+ if (pluginState.directories.length === 1) {
|
|
|
|
+ pluginState.teamDrives.forEach((teamDrive) => {
|
|
|
|
+ folders.splice(0, 0, {
|
|
|
|
+ // Instead of a "normal" id, set it as a query param which will be handled by the server.
|
|
|
|
+ id: '?teamDriveId=' + teamDrive.id,
|
|
|
|
+ name: teamDrive.name,
|
|
|
|
+ kind: teamDrive.kind,
|
|
|
|
+ // Team Drives don't offer an icon, but do have a background image.
|
|
|
|
+ // The extra bit added onto the end crops/resizes the background image, yielding the same icon
|
|
|
|
+ // which is shown in the list of Team Drives within the Google Drive web UI.
|
|
|
|
+ iconLink: teamDrive.backgroundImageLink + '=w16-h16-n'
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ pluginState.folders = folders
|
|
|
|
+ }
|
|
return this.view.render(state)
|
|
return this.view.render(state)
|
|
}
|
|
}
|
|
}
|
|
}
|