diff --git a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts index 5e455898e..bf6d4a5c7 100644 --- a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts @@ -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); } diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index fb17dbaa8..d8b28b67e 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -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.
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);