n8n/packages/nodes-base/nodes/TheHiveProject/actions/log/addAttachment.operation.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-09-04 08:15:52 -07:00
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { theHiveApiRequest } from '../../transport';
import { attachmentsUi, logRLC } from '../../descriptions';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
const properties: INodeProperties[] = [logRLC, attachmentsUi];
const displayOptions = {
show: {
resource: ['log'],
operation: ['addAttachment'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
const logId = this.getNodeParameter('logId', i, '', { extractValue: true }) as string;
const inputDataFields = (
this.getNodeParameter('attachmentsUi.values', i, []) as IDataObject[]
).map((entry) => (entry.field as string).trim());
const attachments = [];
for (const inputDataField of inputDataFields) {
const binaryData = this.helpers.assertBinaryData(i, inputDataField);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, inputDataField);
attachments.push({
value: dataBuffer,
options: {
contentType: binaryData.mimeType,
filename: binaryData.fileName,
},
});
}
await theHiveApiRequest.call(
this,
'POST',
`/v1/log/${logId}/attachments`,
undefined,
undefined,
undefined,
{
Headers: {
'Content-Type': 'multipart/form-data',
},
formData: {
attachments,
},
},
);
const executionData = this.helpers.constructExecutionMetaData(wrapData({ success: true }), {
itemData: { item: i },
});
return executionData;
}