From 2d6a55d82bcc7fab11522322e44bd31a1e101939 Mon Sep 17 00:00:00 2001 From: ricardo Date: Tue, 26 Oct 2021 09:41:52 -0400 Subject: [PATCH 1/6] :zap: Add Google native files support to file:download --- .../nodes/Google/Drive/GoogleDrive.node.ts | 126 +++++++++++++++++- 1 file changed, 124 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 d107487c9c055..f0b4434ec0447 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -291,6 +291,110 @@ export class GoogleDrive implements INodeType { }, }, options: [ + { + displayName: 'Covert Google Docs Files to Format', + name: 'docsToFormat', + type: 'options', + options: [ + { + name: 'MS Word Document', + value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + }, + { + name: 'PDF', + value: 'application/pdf', + }, + { + name: 'Open Office Doc', + value: 'application/vnd.oasis.opendocument.text', + }, + { + name: 'HTML', + value: 'text/html', + }, + { + name: 'Rich Text', + value: 'application/rtf', + }, + ], + default: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + description: 'Format used to export when downloading Google Docs files', + }, + { + displayName: 'Covert Google Drawings Files to Format', + name: 'drawingsToFormat', + type: 'options', + options: [ + { + name: 'JPEG', + value: 'image/jpeg', + }, + { + name: 'PNG', + value: 'image/png', + }, + { + name: 'SVG', + value: 'image/svg+xml', + }, + { + name: 'PDF', + value: 'application/pdf', + }, + ], + default: 'image/jpeg', + description: 'Format used to export when downloading Google Drawings files', + }, + { + displayName: 'Covert Google Slides Files to Format', + name: 'slidesToFormat', + type: 'options', + options: [ + { + name: 'MS PowerPoint', + value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + }, + { + name: 'PDF', + value: 'application/pdf', + }, + { + name: 'Open Office presentation', + value: 'application/vnd.oasis.opendocument.presentation', + }, + { + name: 'Plain Text', + value: 'text/plain', + }, + ], + default: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + description: 'Format used to export when downloading Google Slides files', + }, + { + displayName: 'Covert Google Spreadsheets Files to Format', + name: 'sheetsToFormat', + type: 'options', + options: [ + { + name: 'MS Excel', + value: 'application/x-vnd.oasis.opendocument.spreadsheet', + }, + { + name: 'PDF', + value: 'application/pdf', + }, + { + name: 'CSV', + value: 'text/csv', + }, + { + name: 'Plain Text', + value: 'text/plain', + }, + ], + default: 'application/x-vnd.oasis.opendocument.spreadsheet', + description: 'Format used to export when downloading Google Spreadsheets files', + }, { displayName: 'File Name', name: 'fileName', @@ -2140,7 +2244,25 @@ export class GoogleDrive implements INodeType { json: false, }; - const response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { alt: 'media' }, undefined, requestOptions); + const file = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { fields: 'mimeType' }); + let response; + + if (file.mimeType.includes('vnd.google-apps')) { + const type = file.mimeType.split('.')[2]; + let mime; + if (type === 'document') { + mime = this.getNodeParameter('options.docsToFormat', i, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') as string; + } else if (type === 'presentation') { + mime = this.getNodeParameter('options.slidesToFormat', i, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') as string; + } else if (type === 'spreadsheet') { + mime = this.getNodeParameter('options.sheetsToFormat', i, 'application/x-vnd.oasis.opendocument.spreadsheet') as string; + } else { + mime = this.getNodeParameter('options.drawingsToFormat', i, 'image/jpeg') as string; + } + response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}/export`, {}, { mimeType: mime }, undefined, requestOptions); + } else { + response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { alt: 'media' }, undefined, requestOptions); + } let mimeType: string | undefined; let fileName: string | undefined = undefined; @@ -2325,7 +2447,7 @@ export class GoogleDrive implements INodeType { const properties = this.getNodeParameter('options.propertiesUi.propertyValues', i, []) as IDataObject[]; if (properties.length) { - Object.assign(body, { properties: properties.reduce((obj, value) => Object.assign(obj, { [`${value.key}`]: value.value }), {}) } ); + Object.assign(body, { properties: properties.reduce((obj, value) => Object.assign(obj, { [`${value.key}`]: value.value }), {}) }); } const appProperties = this.getNodeParameter('options.appPropertiesUi.appPropertyValues', i, []) as IDataObject[]; From fdb813618a03c5abd0f1e56054c93cfbe67be2e5 Mon Sep 17 00:00:00 2001 From: ricardo Date: Tue, 26 Oct 2021 09:56:41 -0400 Subject: [PATCH 2/6] :zap: Small fix --- .../nodes-base/nodes/Google/Drive/GoogleDrive.node.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index f0b4434ec0447..68c4bfb0eb977 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -292,7 +292,7 @@ export class GoogleDrive implements INodeType { }, options: [ { - displayName: 'Covert Google Docs Files to Format', + displayName: 'Convert Google Docs Files to Format', name: 'docsToFormat', type: 'options', options: [ @@ -321,7 +321,7 @@ export class GoogleDrive implements INodeType { description: 'Format used to export when downloading Google Docs files', }, { - displayName: 'Covert Google Drawings Files to Format', + displayName: 'Convert Google Drawings Files to Format', name: 'drawingsToFormat', type: 'options', options: [ @@ -346,7 +346,7 @@ export class GoogleDrive implements INodeType { description: 'Format used to export when downloading Google Drawings files', }, { - displayName: 'Covert Google Slides Files to Format', + displayName: 'Convert Google Slides Files to Format', name: 'slidesToFormat', type: 'options', options: [ @@ -371,7 +371,7 @@ export class GoogleDrive implements INodeType { description: 'Format used to export when downloading Google Slides files', }, { - displayName: 'Covert Google Spreadsheets Files to Format', + displayName: 'Convert Google Spreadsheets Files to Format', name: 'sheetsToFormat', type: 'options', options: [ From 20776fd6786185da5e14ab4beeef4893fab62c72 Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 20 Dec 2021 11:30:07 -0500 Subject: [PATCH 3/6] :zap: Improvements --- .../nodes/Google/Drive/GoogleDrive.node.ts | 225 ++++++++++-------- 1 file changed, 122 insertions(+), 103 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index 54a1037dc0032..19bff98dd0a9e 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -239,7 +239,7 @@ export class GoogleDrive implements INodeType { // file:download // ---------------------------------- { - displayName: 'File Id', + displayName: 'File ID', name: 'fileId', type: 'string', default: '', @@ -292,108 +292,126 @@ export class GoogleDrive implements INodeType { }, options: [ { - displayName: 'Convert Google Docs Files to Format', - name: 'docsToFormat', - type: 'options', - options: [ - { - name: 'MS Word Document', - value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - }, - { - name: 'PDF', - value: 'application/pdf', - }, - { - name: 'Open Office Doc', - value: 'application/vnd.oasis.opendocument.text', - }, - { - name: 'HTML', - value: 'text/html', - }, - { - name: 'Rich Text', - value: 'application/rtf', - }, - ], - default: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - description: 'Format used to export when downloading Google Docs files', - }, - { - displayName: 'Convert Google Drawings Files to Format', - name: 'drawingsToFormat', - type: 'options', - options: [ - { - name: 'JPEG', - value: 'image/jpeg', - }, - { - name: 'PNG', - value: 'image/png', - }, - { - name: 'SVG', - value: 'image/svg+xml', - }, - { - name: 'PDF', - value: 'application/pdf', - }, - ], - default: 'image/jpeg', - description: 'Format used to export when downloading Google Drawings files', - }, - { - displayName: 'Convert Google Slides Files to Format', - name: 'slidesToFormat', - type: 'options', - options: [ - { - name: 'MS PowerPoint', - value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - }, - { - name: 'PDF', - value: 'application/pdf', - }, - { - name: 'Open Office presentation', - value: 'application/vnd.oasis.opendocument.presentation', - }, - { - name: 'Plain Text', - value: 'text/plain', - }, - ], - default: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - description: 'Format used to export when downloading Google Slides files', - }, - { - displayName: 'Convert Google Spreadsheets Files to Format', - name: 'sheetsToFormat', - type: 'options', + displayName: 'Google File Conversion', + name: 'googleFileConversion', + type: 'fixedCollection', + typeOptions: { + multipleValues: false, + }, + default: {}, + placeholder: 'Add Conversion', options: [ { - name: 'MS Excel', - value: 'application/x-vnd.oasis.opendocument.spreadsheet', - }, - { - name: 'PDF', - value: 'application/pdf', - }, - { - name: 'CSV', - value: 'text/csv', - }, - { - name: 'Plain Text', - value: 'text/plain', + displayName: 'Conversion', + name: 'conversion', + values: [ + { + displayName: 'Google Docs', + name: 'docsToFormat', + type: 'options', + options: [ + { + name: 'To MS Word', + value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + }, + { + name: 'To PDF', + value: 'application/pdf', + }, + { + name: 'To OpenOffice Doc', + value: 'application/vnd.oasis.opendocument.text', + }, + { + name: 'To HTML', + value: 'text/html', + }, + { + name: 'To Rich Text', + value: 'application/rtf', + }, + ], + default: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + description: 'Format used to export when downloading Google Docs files', + }, + { + displayName: 'Google Drawings', + name: 'drawingsToFormat', + type: 'options', + options: [ + { + name: 'To JPEG', + value: 'image/jpeg', + }, + { + name: 'To PNG', + value: 'image/png', + }, + { + name: 'To SVG', + value: 'image/svg+xml', + }, + { + name: 'To PDF', + value: 'application/pdf', + }, + ], + default: 'image/jpeg', + description: 'Format used to export when downloading Google Drawings files', + }, + { + displayName: 'Google Slides', + name: 'slidesToFormat', + type: 'options', + options: [ + { + name: 'To MS PowerPoint', + value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + }, + { + name: 'To PDF', + value: 'application/pdf', + }, + { + name: 'To OpenOffice Presentation', + value: 'application/vnd.oasis.opendocument.presentation', + }, + { + name: 'To Plain Text', + value: 'text/plain', + }, + ], + default: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + description: 'Format used to export when downloading Google Slides files', + }, + { + displayName: 'Google Sheets', + name: 'sheetsToFormat', + type: 'options', + options: [ + { + name: 'To MS Excel', + value: 'application/x-vnd.oasis.opendocument.spreadsheet', + }, + { + name: 'To PDF', + value: 'application/pdf', + }, + { + name: 'To CSV', + value: 'text/csv', + }, + { + name: 'To Plain Text', + value: 'text/plain', + }, + ], + default: 'application/x-vnd.oasis.opendocument.spreadsheet', + description: 'Format used to export when downloading Google Spreadsheets files', + }, + ], }, ], - default: 'application/x-vnd.oasis.opendocument.spreadsheet', - description: 'Format used to export when downloading Google Spreadsheets files', }, { displayName: 'File Name', @@ -2244,16 +2262,17 @@ export class GoogleDrive implements INodeType { let response; if (file.mimeType.includes('vnd.google-apps')) { + const parameterKey = 'options.googleFileConversion.conversion' const type = file.mimeType.split('.')[2]; let mime; if (type === 'document') { - mime = this.getNodeParameter('options.docsToFormat', i, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') as string; + mime = this.getNodeParameter(`${parameterKey}.docsToFormat`, i, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') as string; } else if (type === 'presentation') { - mime = this.getNodeParameter('options.slidesToFormat', i, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') as string; + mime = this.getNodeParameter(`${parameterKey}.slidesToFormat`, i, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') as string; } else if (type === 'spreadsheet') { - mime = this.getNodeParameter('options.sheetsToFormat', i, 'application/x-vnd.oasis.opendocument.spreadsheet') as string; + mime = this.getNodeParameter(`${parameterKey}.sheetsToFormat`, i, 'application/x-vnd.oasis.opendocument.spreadsheet') as string; } else { - mime = this.getNodeParameter('options.drawingsToFormat', i, 'image/jpeg') as string; + mime = this.getNodeParameter(`${parameterKey}.drawingsToFormat`, i, 'image/jpeg') as string; } response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}/export`, {}, { mimeType: mime }, undefined, requestOptions); } else { From 05bc96480805b5ffdc2a9669b126913ec0c7b2af Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 20 Dec 2021 14:57:46 -0500 Subject: [PATCH 4/6] :zap: Fix lint issue --- packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index 19bff98dd0a9e..7b5e0a28242ed 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -2262,7 +2262,7 @@ export class GoogleDrive implements INodeType { let response; if (file.mimeType.includes('vnd.google-apps')) { - const parameterKey = 'options.googleFileConversion.conversion' + const parameterKey = 'options.googleFileConversion.conversion'; const type = file.mimeType.split('.')[2]; let mime; if (type === 'document') { From 86de887be5024c7b7ffa0ba991821b4c28db3881 Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 20 Dec 2021 15:14:19 -0500 Subject: [PATCH 5/6] :zap: Improvements --- packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index 7b5e0a28242ed..382b64261a893 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -401,10 +401,6 @@ export class GoogleDrive implements INodeType { name: 'To CSV', value: 'text/csv', }, - { - name: 'To Plain Text', - value: 'text/plain', - }, ], default: 'application/x-vnd.oasis.opendocument.spreadsheet', description: 'Format used to export when downloading Google Spreadsheets files', @@ -2274,6 +2270,7 @@ export class GoogleDrive implements INodeType { } else { mime = this.getNodeParameter(`${parameterKey}.drawingsToFormat`, i, 'image/jpeg') as string; } + console.log(mime); response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}/export`, {}, { mimeType: mime }, undefined, requestOptions); } else { response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { alt: 'media' }, undefined, requestOptions); From 9ab721246efede1d4ab8341e228868f93abb9593 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Tue, 21 Dec 2021 23:28:40 +0100 Subject: [PATCH 6/6] :zap: Remove console.log --- packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index 382b64261a893..9634c07e7fe31 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -2270,7 +2270,6 @@ export class GoogleDrive implements INodeType { } else { mime = this.getNodeParameter(`${parameterKey}.drawingsToFormat`, i, 'image/jpeg') as string; } - console.log(mime); response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}/export`, {}, { mimeType: mime }, undefined, requestOptions); } else { response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { alt: 'media' }, undefined, requestOptions);