Handle comma separated binary properties (Gmail) (#1711)

This commit is contained in:
Ricardo Espinoza 2021-04-30 15:44:46 -04:00 committed by GitHub
parent 029b1390ee
commit 444fe64bc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 61 deletions

View file

@ -209,7 +209,8 @@ export const draftFields = [
name: 'property', name: 'property',
type: 'string', type: 'string',
default: '', default: '',
description: 'Name of the binary property containing the data to be added to the email as an attachment', description: `Name of the binary property containing the data to be added to the email as an attachment.</br>
Multiples can be set separated by comma.`,
}, },
], ],
}, },

View file

@ -325,28 +325,29 @@ export class Gmail implements INodeType {
if (additionalFields.attachmentsUi) { if (additionalFields.attachmentsUi) {
const attachmentsUi = additionalFields.attachmentsUi as IDataObject; const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
let attachmentsBinary = []; const attachmentsBinary = [];
if (!isEmpty(attachmentsUi)) { if (!isEmpty(attachmentsUi)) {
if (attachmentsUi.hasOwnProperty('attachmentsBinary') if (attachmentsUi.hasOwnProperty('attachmentsBinary')
&& !isEmpty(attachmentsUi.attachmentsBinary) && !isEmpty(attachmentsUi.attachmentsBinary)
&& items[i].binary) { && items[i].binary) {
// @ts-ignore for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
attachmentsBinary = attachmentsUi.attachmentsBinary.map((value) => { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary!.hasOwnProperty(value.property)) { if (items[i].binary![binaryProperty] !== undefined) {
const aux: IAttachments = { name: '', content: '', type: '' }; const binaryData = items[i].binary![binaryProperty];
aux.name = items[i].binary![value.property].fileName || 'unknown'; attachmentsBinary.push({
aux.content = items[i].binary![value.property].data; name: binaryData.fileName || 'unknown',
aux.type = items[i].binary![value.property].mimeType; content: binaryData.data,
return aux; type: binaryData.mimeType,
}
}); });
} }
}
}
}
qs = { qs = {
userId: 'me', userId: 'me',
uploadType: 'media', uploadType: 'media',
}; };
attachmentsList = attachmentsBinary; attachmentsList = attachmentsBinary;
} }
} }
@ -408,32 +409,32 @@ export class Gmail implements INodeType {
if (additionalFields.attachmentsUi) { if (additionalFields.attachmentsUi) {
const attachmentsUi = additionalFields.attachmentsUi as IDataObject; const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
let attachmentsBinary = []; const attachmentsBinary = [];
if (!isEmpty(attachmentsUi)) { if (!isEmpty(attachmentsUi)) {
if (attachmentsUi.hasOwnProperty('attachmentsBinary') if (attachmentsUi.hasOwnProperty('attachmentsBinary')
&& !isEmpty(attachmentsUi.attachmentsBinary) && !isEmpty(attachmentsUi.attachmentsBinary)
&& items[i].binary) { && items[i].binary) {
// @ts-ignore for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
attachmentsBinary = attachmentsUi.attachmentsBinary.map((value) => { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary!.hasOwnProperty(value.property)) { if (items[i].binary![binaryProperty] !== undefined) {
const aux: IAttachments = { name: '', content: '', type: '' }; const binaryData = items[i].binary![binaryProperty];
aux.name = items[i].binary![value.property].fileName || 'unknown'; attachmentsBinary.push({
aux.content = items[i].binary![value.property].data; name: binaryData.fileName || 'unknown',
aux.type = items[i].binary![value.property].mimeType; content: binaryData.data,
return aux; type: binaryData.mimeType,
}
}); });
} }
}
}
}
qs = { qs = {
userId: 'me', userId: 'me',
uploadType: 'media', uploadType: 'media',
}; };
attachmentsList = attachmentsBinary; attachmentsList = attachmentsBinary;
} }
} }
// if no recipient is defined then grab the one who sent the email // if no recipient is defined then grab the one who sent the email
if (toStr === '') { if (toStr === '') {
endpoint = `/gmail/v1/users/me/messages/${id}`; endpoint = `/gmail/v1/users/me/messages/${id}`;
@ -628,28 +629,29 @@ export class Gmail implements INodeType {
if (additionalFields.attachmentsUi) { if (additionalFields.attachmentsUi) {
const attachmentsUi = additionalFields.attachmentsUi as IDataObject; const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
let attachmentsBinary = []; const attachmentsBinary = [];
if (!isEmpty(attachmentsUi)) { if (!isEmpty(attachmentsUi)) {
if (attachmentsUi.hasOwnProperty('attachmentsBinary') if (attachmentsUi.hasOwnProperty('attachmentsBinary')
&& !isEmpty(attachmentsUi.attachmentsBinary) && !isEmpty(attachmentsUi.attachmentsBinary)
&& items[i].binary) { && items[i].binary) {
// @ts-ignore for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
attachmentsBinary = attachmentsUi.attachmentsBinary.map((value) => { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary!.hasOwnProperty(value.property)) { if (items[i].binary![binaryProperty] !== undefined) {
const aux: IAttachments = { name: '', content: '', type: '' }; const binaryData = items[i].binary![binaryProperty];
aux.name = items[i].binary![value.property].fileName || 'unknown'; attachmentsBinary.push({
aux.content = items[i].binary![value.property].data; name: binaryData.fileName || 'unknown',
aux.type = items[i].binary![value.property].mimeType; content: binaryData.data,
return aux; type: binaryData.mimeType,
}
}); });
} }
}
}
}
qs = { qs = {
userId: 'me', userId: 'me',
uploadType: 'media', uploadType: 'media',
}; };
attachmentsList = attachmentsBinary; attachmentsList = attachmentsBinary;
} }
} }

View file

@ -226,30 +226,6 @@ export const messageFields = [
}, },
default: {}, default: {},
options: [ options: [
{
displayName: 'CC Email',
name: 'ccList',
type: 'string',
description: 'The email addresses of the copy recipients.',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add CC Email',
},
placeholder: 'info@example.com',
default: [],
},
{
displayName: 'BCC Email',
name: 'bccList',
type: 'string',
description: 'The email addresses of the blind copy recipients.',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add BCC Email',
},
placeholder: 'info@example.com',
default: [],
},
{ {
displayName: 'Attachments', displayName: 'Attachments',
name: 'attachmentsUi', name: 'attachmentsUi',
@ -268,7 +244,8 @@ export const messageFields = [
name: 'property', name: 'property',
type: 'string', type: 'string',
default: '', default: '',
description: 'Name of the binary properties which contain data which should be added to email as attachment', description: `Name of the binary property containing the data to be added to the email as an attachment.</br>
Multiples can be set separated by comma.`,
}, },
], ],
}, },
@ -276,6 +253,30 @@ export const messageFields = [
default: '', default: '',
description: 'Array of supported attachments to add to the message.', description: 'Array of supported attachments to add to the message.',
}, },
{
displayName: 'BCC Email',
name: 'bccList',
type: 'string',
description: 'The email addresses of the blind copy recipients.',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add BCC Email',
},
placeholder: 'info@example.com',
default: [],
},
{
displayName: 'CC Email',
name: 'ccList',
type: 'string',
description: 'The email addresses of the copy recipients.',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add CC Email',
},
placeholder: 'info@example.com',
default: [],
},
], ],
}, },
{ {