mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Add Google native files support to file:download - Google Drive (#2372)
* ⚡ Add Google native files support to file:download * ⚡ Small fix * ⚡ Improvements * ⚡ Fix lint issue * ⚡ Improvements * ⚡ Remove console.log Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
419c719f90
commit
cbe2fc2210
|
@ -239,7 +239,7 @@ export class GoogleDrive implements INodeType {
|
|||
// file:download
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'File Id',
|
||||
displayName: 'File ID',
|
||||
name: 'fileId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
|
@ -291,6 +291,124 @@ export class GoogleDrive implements INodeType {
|
|||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Google File Conversion',
|
||||
name: 'googleFileConversion',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: false,
|
||||
},
|
||||
default: {},
|
||||
placeholder: 'Add Conversion',
|
||||
options: [
|
||||
{
|
||||
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',
|
||||
},
|
||||
],
|
||||
default: 'application/x-vnd.oasis.opendocument.spreadsheet',
|
||||
description: 'Format used to export when downloading Google Spreadsheets files',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'File Name',
|
||||
name: 'fileName',
|
||||
|
@ -2136,7 +2254,26 @@ 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 parameterKey = 'options.googleFileConversion.conversion';
|
||||
const type = file.mimeType.split('.')[2];
|
||||
let mime;
|
||||
if (type === 'document') {
|
||||
mime = this.getNodeParameter(`${parameterKey}.docsToFormat`, i, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') as string;
|
||||
} else if (type === 'presentation') {
|
||||
mime = this.getNodeParameter(`${parameterKey}.slidesToFormat`, i, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') as string;
|
||||
} else if (type === 'spreadsheet') {
|
||||
mime = this.getNodeParameter(`${parameterKey}.sheetsToFormat`, i, 'application/x-vnd.oasis.opendocument.spreadsheet') as string;
|
||||
} else {
|
||||
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 {
|
||||
response = await googleApiRequest.call(this, 'GET', `/drive/v3/files/${fileId}`, {}, { alt: 'media' }, undefined, requestOptions);
|
||||
}
|
||||
|
||||
let mimeType: string | undefined;
|
||||
let fileName: string | undefined = undefined;
|
||||
|
@ -2321,7 +2458,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[];
|
||||
|
|
Loading…
Reference in a new issue