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