fix(Move Binary Data Node): Stringify objects before encoding them in MoveBinaryData (#4882)

* stringify objects before encoding them objects in MoveBinaryData

* add fileSize and fileType on MoveBinaryData converted data

* show `view` option for text files as well

* improve how JSON binary data is shown in the UI
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2022-12-11 14:10:54 +01:00
committed by GitHub
parent f4481e24e8
commit 3b969d2cd1
10 changed files with 80 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import { get, set, unset } from 'lodash';
import prettyBytes from 'pretty-bytes';
import { BINARY_ENCODING, IExecuteFunctions } from 'n8n-core';
@@ -12,6 +13,7 @@ import {
INodeTypeDescription,
jsonParse,
NodeOperationError,
fileTypeFromMimeType,
} from 'n8n-workflow';
import iconv from 'iconv-lite';
@@ -415,20 +417,26 @@ export class MoveBinaryData implements INodeType {
newItem.binary = {};
}
const mimeType = (options.mimeType as string) || 'application/json';
const convertedValue: IBinaryData = {
data: '',
mimeType,
fileType: fileTypeFromMimeType(mimeType),
};
if (options.dataIsBase64 !== true) {
if (options.useRawData !== true) {
if (options.useRawData !== true || typeof value === 'object') {
value = JSON.stringify(value);
}
value = iconv
.encode(value as string, encoding, { addBOM: options.addBOM as boolean })
.toString(BINARY_ENCODING);
}
convertedValue.fileSize = prettyBytes(value.length);
const convertedValue: IBinaryData = {
data: value as string,
mimeType: (options.mimeType as string) || 'application/json',
};
convertedValue.data = iconv
.encode(value, encoding, { addBOM: options.addBOM as boolean })
.toString(BINARY_ENCODING);
} else {
convertedValue.data = value as unknown as string;
}
if (options.fileName) {
convertedValue.fileName = options.fileName as string;