mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 14:09:43 -08:00
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
|
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;
|
||
|
}
|