🐛 Fix bug with Google Drive node (#1443)

* 🐛 Fix bug with Google Drive node

The bug did not let the user to select the fields he wanted the API to return in the resources Folder and File.

*  Change default to not break anything and hide not needed options

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-02-15 03:02:47 -05:00 committed by GitHub
parent 4b8b08450f
commit 19412b6025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 56 deletions

View file

@ -45,8 +45,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
options.headers!.Authorization = `Bearer ${access_token}`;
//@ts-ignore
return await this.helpers.request(options);
return await this.helpers.request!(options);
} else {
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, 'googleDriveOAuth2Api', options);
@ -140,6 +139,5 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa
json: true,
};
//@ts-ignore
return this.helpers.request(options);
return this.helpers.request!(options);
}

View file

@ -10,13 +10,13 @@ import {
INodeTypeDescription,
} from 'n8n-workflow';
import uuid = require('uuid');
import {
googleApiRequest,
googleApiRequestAllItems,
} from './GenericFunctions';
import uuid = require('uuid');
export class GoogleDrive implements INodeType {
description: INodeTypeDescription = {
displayName: 'Google Drive',
@ -733,6 +733,24 @@ export class GoogleDrive implements INodeType {
placeholder: 'invoice_1.pdf',
description: 'The name the file should be saved as.',
},
// ----------------------------------
{
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
default: false,
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'file',
],
},
},
description: 'By default the response only contain the ID of the file.<br />If this option gets activated it will resolve the data automatically.',
},
{
displayName: 'Parents',
name: 'parents',
@ -787,9 +805,15 @@ export class GoogleDrive implements INodeType {
placeholder: 'Add Option',
default: {},
displayOptions: {
hide: {
resource: [
'drive',
show: {
'/operation': [
'copy',
'list',
'share',
],
'/resource': [
'file',
'folder',
],
},
},
@ -838,48 +862,8 @@ export class GoogleDrive implements INodeType {
displayOptions: {
show: {
'/operation': [
'share',
],
'/resource': [
'file',
'folder',
],
},
},
options: [
{
name: '*',
value: '*',
description: 'All fields.',
},
{
name: 'Email Address',
value: 'emailAddress',
},
{
name: 'Display Name',
value: 'displayName',
},
{
name: 'Deleted',
value: 'deleted',
},
],
default: [],
description: 'The fields to return.',
},
{
displayName: 'Fields',
name: 'fields',
type: 'multiOptions',
displayOptions: {
hide: {
'/operation': [
'share',
],
'/resource': [
'file',
'folder',
'list',
'copy',
],
},
},
@ -1976,7 +1960,7 @@ export class GoogleDrive implements INodeType {
// ----------------------------------
// upload
// ----------------------------------
const options = this.getNodeParameter('options', i) as IDataObject;
const resolveData = this.getNodeParameter('resolveData', 0) as boolean;
let mimeType = 'text/plain';
let body;
@ -2042,6 +2026,10 @@ export class GoogleDrive implements INodeType {
response = await googleApiRequest.call(this, 'PATCH', `/drive/v3/files/${JSON.parse(response).id}`, body, qs);
if (resolveData === true) {
response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${response.id}`, {}, { fields: '*' });
}
returnData.push(response as IDataObject);
}
@ -2102,10 +2090,6 @@ export class GoogleDrive implements INodeType {
Object.assign(qs, options);
if (qs.fields) {
qs.fields = (qs.fields as string[]).join(',');
}
const response = await googleApiRequest.call(this, 'POST', `/drive/v3/files/${fileId}/permissions`, body, qs);
returnData.push(response as IDataObject);