mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 13:14:07 -08:00
372d5c7d01
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
|
|
|
import { toFileOptions, toFileProperties } from '../description';
|
|
import { generatePairedItemData } from '@utils/utilities';
|
|
import type { JsonToSpreadsheetBinaryFormat, JsonToSpreadsheetBinaryOptions } from '@utils/binary';
|
|
import { convertJsonToSpreadsheetBinary } from '@utils/binary';
|
|
|
|
export const description: INodeProperties[] = [...toFileProperties, toFileOptions];
|
|
|
|
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
|
const returnData: INodeExecutionData[] = [];
|
|
|
|
const pairedItem = generatePairedItemData(items.length);
|
|
|
|
try {
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
|
|
const fileFormat = this.getNodeParameter('fileFormat', 0) as JsonToSpreadsheetBinaryFormat;
|
|
const options = this.getNodeParameter('options', 0, {}) as JsonToSpreadsheetBinaryOptions;
|
|
|
|
const binaryData = await convertJsonToSpreadsheetBinary.call(this, items, fileFormat, options);
|
|
|
|
const newItem: INodeExecutionData = {
|
|
json: {},
|
|
binary: {
|
|
[binaryPropertyName]: binaryData,
|
|
},
|
|
pairedItem,
|
|
};
|
|
|
|
returnData.push(newItem);
|
|
} catch (error) {
|
|
if (this.continueOnFail()) {
|
|
returnData.push({
|
|
json: {
|
|
error: error.message,
|
|
},
|
|
pairedItem,
|
|
});
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
return returnData;
|
|
}
|