@uppy/google-drive
Advanced tools
Comparing version 0.27.3 to 0.27.4
@@ -15,3 +15,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var ProviderViews = require('@uppy/provider-views'); | ||
var DriveProviderViews = require('./DriveProviderViews'); | ||
@@ -60,3 +60,3 @@ var _require3 = require('preact'), | ||
GoogleDrive.prototype.install = function install() { | ||
this.view = new ProviderViews(this); | ||
this.view = new DriveProviderViews(this); | ||
// Set default state for Google Drive | ||
@@ -70,3 +70,6 @@ this.setPluginState({ | ||
filterInput: '', | ||
isSearchVisible: false | ||
isSearchVisible: false, | ||
hasTeamDrives: false, | ||
teamDrives: [], | ||
teamDriveId: '' | ||
}); | ||
@@ -89,5 +92,16 @@ | ||
this.view.getFolder('root'); | ||
this.getTeamDrives(); | ||
} | ||
}; | ||
GoogleDrive.prototype.getTeamDrives = function getTeamDrives() { | ||
var _this2 = this; | ||
this[this.id].get(this.GoogleDrive.id + '/list/?listTeamDrives=true').then(function (payload) { | ||
if (payload.teamDrives && payload.teamDrives.length) { | ||
_this2.setPluginState({ hasTeamDrives: true, teamDrives: payload.teamDrives }); | ||
} | ||
}); | ||
}; | ||
GoogleDrive.prototype.getUsername = function getUsername(data) { | ||
@@ -144,6 +158,6 @@ for (var _iterator = data.files, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
GoogleDrive.prototype.getItemSubList = function getItemSubList(item) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return item.files.filter(function (i) { | ||
return _this2.isFolder(i) || !i.mimeType.startsWith('application/vnd.google'); | ||
return _this3.isFolder(i) || !i.mimeType.startsWith('application/vnd.google'); | ||
}); | ||
@@ -165,2 +179,9 @@ }; | ||
GoogleDrive.prototype.getItemRequestPath = function 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); | ||
@@ -178,2 +199,30 @@ }; | ||
GoogleDrive.prototype.render = function render(state) { | ||
var pluginState = this.getPluginState(); | ||
// If the user has access to any Team Drives, handle them as needed. | ||
if (pluginState.hasTeamDrives) { | ||
var folders = pluginState.folders; | ||
// Remove any Team Drives we've previously pushed into the list of folders. | ||
folders = folders.filter(function (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(function (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); | ||
@@ -180,0 +229,0 @@ }; |
{ | ||
"name": "@uppy/google-drive", | ||
"description": "The Google Drive plugin for Uppy lets users import files from their Google Drive account", | ||
"version": "0.27.3", | ||
"version": "0.27.4", | ||
"license": "MIT", | ||
@@ -26,3 +26,3 @@ "main": "lib/index.js", | ||
"@uppy/companion-client": "0.27.2", | ||
"@uppy/provider-views": "0.27.2", | ||
"@uppy/provider-views": "0.27.3", | ||
"@uppy/utils": "0.27.1", | ||
@@ -32,7 +32,8 @@ "preact": "^8.2.9" | ||
"devDependencies": { | ||
"@uppy/core": "0.27.1" | ||
"@uppy/core": "0.27.2" | ||
}, | ||
"peerDependencies": { | ||
"@uppy/core": "^0.27.0" | ||
} | ||
}, | ||
"gitHead": "4819ff33ce676cdc4ad8208b616829b15fc059c6" | ||
} |
const { Plugin } = require('@uppy/core') | ||
const { Provider } = require('@uppy/companion-client') | ||
const ProviderViews = require('@uppy/provider-views') | ||
const DriveProviderViews = require('./DriveProviderViews') | ||
const { h } = require('preact') | ||
@@ -35,3 +35,3 @@ | ||
install () { | ||
this.view = new ProviderViews(this) | ||
this.view = new DriveProviderViews(this) | ||
// Set default state for Google Drive | ||
@@ -45,3 +45,6 @@ this.setPluginState({ | ||
filterInput: '', | ||
isSearchVisible: false | ||
isSearchVisible: false, | ||
hasTeamDrives: false, | ||
teamDrives: [], | ||
teamDriveId: '' | ||
}) | ||
@@ -64,5 +67,15 @@ | ||
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) { | ||
@@ -111,2 +124,9 @@ for (const item of data.files) { | ||
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) | ||
@@ -124,4 +144,32 @@ } | ||
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) | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19378
10
373
+ Added@uppy/provider-views@0.27.3(transitive)
- Removed@uppy/provider-views@0.27.2(transitive)
Updated@uppy/provider-views@0.27.3