mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Unify binary-data assertion across all nodes (no-changelog) (#5624)
This commit is contained in:
committed by
GitHub
parent
01a2160b3b
commit
5eb0d52459
@@ -1,18 +1,16 @@
|
||||
import type { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import { cortexApiRequest, getEntityLabel, prepareParameters, splitTags } from './GenericFunctions';
|
||||
|
||||
import { analyzerFields, analyzersOperations } from './AnalyzerDescriptions';
|
||||
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { responderFields, respondersOperations } from './ResponderDescription';
|
||||
|
||||
@@ -193,24 +191,8 @@ export class Cortex implements INodeType {
|
||||
}
|
||||
|
||||
if (observableType === 'file') {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
||||
|
||||
if (item.binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item has no binary property called "${binaryPropertyName}"`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
||||
const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
|
||||
const options = {
|
||||
@@ -218,8 +200,8 @@ export class Cortex implements INodeType {
|
||||
data: {
|
||||
value: fileBufferData,
|
||||
options: {
|
||||
contentType: item.binary[binaryPropertyName].mimeType,
|
||||
filename: item.binary[binaryPropertyName].fileName,
|
||||
contentType: binaryData.mimeType,
|
||||
filename: binaryData.fileName,
|
||||
},
|
||||
},
|
||||
_json: JSON.stringify({
|
||||
@@ -337,27 +319,8 @@ export class Cortex implements INodeType {
|
||||
element.data = artifactvalue.data as string;
|
||||
|
||||
if (artifactvalue.dataType === 'file') {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'No binary data exists on item!',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryPropertyName = artifactvalue.binaryProperty as string;
|
||||
|
||||
if (item.binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item has no binary property called "${binaryPropertyName}"`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryData = item.binary[binaryPropertyName];
|
||||
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
||||
|
||||
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
|
||||
}
|
||||
@@ -373,24 +336,9 @@ export class Cortex implements INodeType {
|
||||
// deal with file observable
|
||||
|
||||
if ((body.data as IDataObject).dataType === 'file') {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
|
||||
const binaryPropertyName = (body.data as IDataObject)
|
||||
.binaryPropertyName as string;
|
||||
if (item.binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item has no binary property called "${binaryPropertyName}"`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
||||
const fileBufferData = await this.helpers.getBinaryDataBuffer(
|
||||
i,
|
||||
binaryPropertyName,
|
||||
@@ -398,14 +346,14 @@ export class Cortex implements INodeType {
|
||||
const sha256 = createHash('sha256').update(fileBufferData).digest('hex');
|
||||
|
||||
(body.data as IDataObject).attachment = {
|
||||
name: item.binary[binaryPropertyName].fileName,
|
||||
name: binaryData.fileName,
|
||||
hashes: [
|
||||
sha256,
|
||||
createHash('sha1').update(fileBufferData).digest('hex'),
|
||||
createHash('md5').update(fileBufferData).digest('hex'),
|
||||
],
|
||||
size: fileBufferData.byteLength,
|
||||
contentType: item.binary[binaryPropertyName].mimeType,
|
||||
contentType: binaryData.mimeType,
|
||||
id: sha256,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user