From f7bd3060bdb91363e205955dbc33f3dc937539ff Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 12 Mar 2021 05:24:40 -0500 Subject: [PATCH] :zap: Add operation file:update to Google Drive node (#1523) * :zap: Add operation file:update to Google Drive node * :zap: Improvements * :zap: Small changes Co-authored-by: Jan Oberhauser --- .../nodes/Google/Drive/GoogleDrive.node.ts | 196 +++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index d654e9fa76..14e58f3826 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -136,6 +136,11 @@ export class GoogleDrive implements INodeType { value: 'share', description: 'Share a file', }, + { + name: 'Update', + value: 'update', + description: 'Update a file', + }, { name: 'Upload', value: 'upload', @@ -205,7 +210,6 @@ export class GoogleDrive implements INodeType { description: 'The ID of the file to copy.', }, - // ---------------------------------- // file/folder:delete // ---------------------------------- @@ -710,7 +714,174 @@ export class GoogleDrive implements INodeType { placeholder: '', description: 'Name of the binary property which contains
the data for the file to be uploaded.', }, - + // ---------------------------------- + // file:update + // ---------------------------------- + { + displayName: 'ID', + name: 'fileId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'update', + ], + resource: [ + 'file', + ], + }, + }, + description: 'The ID of the file to update.', + }, + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + operation: [ + 'update', + ], + resource: [ + 'file', + ], + }, + }, + options: [ + { + displayName: 'Keep Revision Forever', + name: 'keepRevisionForever', + type: 'boolean', + default: false, + description: `Whether to set the 'keepForever' field in the new head revision.
+ his is only applicable to files with binary content in Google Drive.
+ Only 200 revisions for the file can be kept forever. If the limit is reached, try deleting pinned revisions.`, + }, + { + displayName: 'OCR Language', + name: 'ocrLanguage', + type: 'string', + default: '', + description: `A language hint for OCR processing during image import (ISO 639-1 code).`, + }, + { + displayName: 'Parent ID', + name: 'parentId', + type: 'string', + default: '', + description: `The ID of the parent to set.`, + }, + { + displayName: 'Use Content As Indexable Text', + name: 'useContentAsIndexableText', + type: 'boolean', + default: false, + description: `Whether to use the uploaded content as indexable text.`, + }, + ], + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + operation: [ + 'update', + ], + resource: [ + 'file', + ], + }, + }, + options: [ + { + displayName: 'Fields', + name: 'fields', + type: 'multiOptions', + options: [ + { + name: '*', + value: '*', + description: 'All fields.', + }, + { + name: 'explicitlyTrashed', + value: 'explicitlyTrashed', + }, + { + name: 'exportLinks', + value: 'exportLinks', + }, + { + name: 'iconLink', + value: 'iconLink', + }, + { + name: 'hasThumbnail', + value: 'hasThumbnail', + }, + { + name: 'id', + value: 'id', + }, + { + name: 'kind', + value: 'kind', + }, + { + name: 'name', + value: 'name', + }, + { + name: 'mimeType', + value: 'mimeType', + }, + { + name: 'permissions', + value: 'permissions', + }, + { + name: 'shared', + value: 'shared', + }, + { + name: 'spaces', + value: 'spaces', + }, + { + name: 'starred', + value: 'starred', + }, + { + name: 'thumbnailLink', + value: 'thumbnailLink', + }, + { + name: 'trashed', + value: 'trashed', + }, + { + name: 'version', + value: 'version', + }, + { + name: 'webViewLink', + value: 'webViewLink', + }, + ], + required: true, + default: [], + description: 'The fields to return.', + }, + ], + }, // ---------------------------------- // file:upload // ---------------------------------- @@ -2032,6 +2203,27 @@ export class GoogleDrive implements INodeType { } returnData.push(response as IDataObject); + } else if (operation === 'update') { + // ---------------------------------- + // file:update + // ---------------------------------- + + const id = this.getNodeParameter('fileId', i) as string; + const updateFields = this.getNodeParameter('updateFields', i, {}) as IDataObject; + + const qs: IDataObject = { + supportsAllDrives: true, + }; + + Object.assign(qs, options); + + qs.fields = queryFields; + + if (updateFields.parentId && updateFields.parentId !== '') + qs.addParents = updateFields.parentId; + + const responseData = await googleApiRequest.call(this, 'PATCH', `/drive/v3/files/${id}`, {}, qs); + returnData.push(responseData as IDataObject); } } else if (resource === 'folder') {