feat(Jira Software Node): Support binary streaming for very large binary files (#5589)

Move from buffer to binary streaming
This commit is contained in:
agobrech 2023-03-01 18:14:07 +01:00 committed by GitHub
parent f3c943ef81
commit f61d779667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
import type { Readable } from 'stream';
import mergeWith from 'lodash.mergewith'; import mergeWith from 'lodash.mergewith';
import type { IExecuteFunctions } from 'n8n-core'; import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core';
import type { import type {
IBinaryKeyData, IBinaryKeyData,
@ -1061,12 +1063,9 @@ export class Jira implements INodeType {
itemIndex: i, itemIndex: i,
}); });
} }
let uploadData: Buffer | Readable;
const item = items[i].binary as IBinaryKeyData; const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName]; const binaryData = item[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) { if (binaryData === undefined) {
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
@ -1075,6 +1074,12 @@ export class Jira implements INodeType {
); );
} }
if (binaryData.id) {
uploadData = this.helpers.getBinaryStream(binaryData.id);
} else {
uploadData = Buffer.from(binaryData.data, BINARY_ENCODING);
}
responseData = await jiraSoftwareCloudApiRequest.call( responseData = await jiraSoftwareCloudApiRequest.call(
this, this,
`/api/${apiVersion}/issue/${issueKey}/attachments`, `/api/${apiVersion}/issue/${issueKey}/attachments`,
@ -1085,7 +1090,7 @@ export class Jira implements INodeType {
{ {
formData: { formData: {
file: { file: {
value: binaryDataBuffer, value: uploadData,
options: { options: {
filename: binaryData.fileName, filename: binaryData.fileName,
}, },
@ -1154,7 +1159,7 @@ export class Jira implements INodeType {
{}, {},
{}, {},
attachment?.json.content as string, attachment?.json.content as string,
{ json: false, encoding: null }, { json: false, encoding: null, useStream: true },
); );
(returnData[index].binary as IBinaryKeyData)[binaryPropertyName] = (returnData[index].binary as IBinaryKeyData)[binaryPropertyName] =
@ -1205,7 +1210,7 @@ export class Jira implements INodeType {
{}, {},
{}, {},
attachment.json.content as string, attachment.json.content as string,
{ json: false, encoding: null }, { json: false, encoding: null, useStream: true },
); );
(returnData[index].binary as IBinaryKeyData)[binaryPropertyName] = (returnData[index].binary as IBinaryKeyData)[binaryPropertyName] =
await this.helpers.prepareBinaryData( await this.helpers.prepareBinaryData(