From 8789e9be3c06090ff51a3cf19f350ec6f79a3268 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 13 Dec 2019 11:04:01 -0600 Subject: [PATCH] :sparkles: Add copy-file functionality to GoogleDrive-Node --- .../nodes/Google/GoogleDrive.node.ts | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Google/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/GoogleDrive.node.ts index 2377910c25..84208811d7 100644 --- a/packages/nodes-base/nodes/Google/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/GoogleDrive.node.ts @@ -71,6 +71,11 @@ export class GoogleDrive implements INodeType { }, }, options: [ + { + name: 'Copy', + value: 'copy', + description: 'Copy a file', + }, { name: 'Delete', value: 'delete', @@ -128,6 +133,29 @@ export class GoogleDrive implements INodeType { // file // ---------------------------------- + // ---------------------------------- + // file:copy + // ---------------------------------- + { + displayName: 'ID', + name: 'fileId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'copy' + ], + resource: [ + 'file', + ], + }, + }, + description: 'The ID of the file to copy.', + }, + + // ---------------------------------- // file/folder:delete // ---------------------------------- @@ -635,6 +663,45 @@ export class GoogleDrive implements INodeType { default: [], description: 'The fields to return.', }, + + { + displayName: 'File Name', + name: 'name', + type: 'string', + displayOptions: { + show: { + '/operation': [ + 'copy' + ], + '/resource': [ + 'file', + ], + }, + }, + default: '', + placeholder: 'invoice_1.pdf', + description: 'The name the file should be saved as.', + }, + { + displayName: 'Parents', + name: 'parents', + type: 'string', + displayOptions: { + show: { + '/operation': [ + 'copy' + ], + '/resource': [ + 'file', + ], + }, + }, + typeOptions: { + multipleValues: true, + }, + default: [], + description: 'The IDs of the parent folders the file should be saved in.', + }, { displayName: 'Spaces', name: 'spaces', @@ -780,7 +847,31 @@ export class GoogleDrive implements INodeType { } if (resource === 'file') { - if (operation === 'download') { + if (operation === 'copy') { + // ---------------------------------- + // copy + // ---------------------------------- + + const fileId = this.getNodeParameter('fileId', i) as string; + + const copyOptions = { + fileId, + fields: queryFields, + requestBody: {} as IDataObject, + }; + + const optionProperties = ['name', 'parents']; + for (const propertyName of optionProperties) { + if (options[propertyName] !== undefined) { + copyOptions.requestBody[propertyName] = options[propertyName]; + } + } + + const response = await drive.files.copy(copyOptions); + + returnData.push(response.data as IDataObject); + + } else if (operation === 'download') { // ---------------------------------- // download // ----------------------------------