mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-27 21:49:41 -08:00
62c096710f
- Fix autofixable violations - Remove unused directives - Allow for PascalCased variables - needed for dynamically imported or assigned classes, decorators, routers, etc.
90 lines
2.1 KiB
TypeScript
90 lines
2.1 KiB
TypeScript
import type {
|
|
IDataObject,
|
|
IExecuteFunctions,
|
|
INodeExecutionData,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
import { theHiveApiRequest } from '../../transport';
|
|
import { attachmentsUi, caseRLC } from '../../descriptions';
|
|
import { updateDisplayOptions, wrapData } from '@utils/utilities';
|
|
|
|
const properties: INodeProperties[] = [
|
|
caseRLC,
|
|
attachmentsUi,
|
|
{
|
|
displayName: 'Options',
|
|
name: 'options',
|
|
type: 'collection',
|
|
placeholder: 'Add Option',
|
|
default: {},
|
|
options: [
|
|
{
|
|
displayName: 'Rename Files',
|
|
name: 'canRename',
|
|
type: 'boolean',
|
|
description: 'Whether to rename the file in case a file with the same name already exists',
|
|
default: false,
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const displayOptions = {
|
|
show: {
|
|
resource: ['case'],
|
|
operation: ['addAttachment'],
|
|
},
|
|
};
|
|
|
|
export const description = updateDisplayOptions(displayOptions, properties);
|
|
|
|
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
|
|
let responseData: IDataObject | IDataObject[] = [];
|
|
|
|
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
|
|
const canRename = this.getNodeParameter('options.canRename', i, false) as boolean;
|
|
|
|
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,
|
|
},
|
|
});
|
|
}
|
|
|
|
responseData = await theHiveApiRequest.call(
|
|
this,
|
|
'POST',
|
|
`/v1/case/${caseId}/attachments`,
|
|
undefined,
|
|
undefined,
|
|
undefined,
|
|
{
|
|
Headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
formData: {
|
|
attachments,
|
|
canRename: JSON.stringify(canRename),
|
|
},
|
|
},
|
|
);
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
|
|
itemData: { item: i },
|
|
});
|
|
|
|
return executionData;
|
|
}
|