mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
refactor(Telegram Node): Stream binary data for uploads and downloads (#5261)
This commit is contained in:
parent
0a7ea89633
commit
266c50fb1e
|
@ -1,4 +1,5 @@
|
|||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import type { Readable } from 'stream';
|
||||
import { BINARY_ENCODING, IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
|
@ -1962,7 +1963,6 @@ export class Telegram implements INodeType {
|
|||
if (binaryData) {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
|
||||
const itemBinaryData = items[i].binary![binaryPropertyName];
|
||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
const propertyName = getPropertyName(operation);
|
||||
const fileName = this.getNodeParameter('additionalFields.fileName', 0, '') as string;
|
||||
|
||||
|
@ -1979,10 +1979,17 @@ export class Telegram implements INodeType {
|
|||
|
||||
body.disable_notification = body.disable_notification?.toString() || 'false';
|
||||
|
||||
let uploadData: Buffer | Readable;
|
||||
if (itemBinaryData.id) {
|
||||
uploadData = this.helpers.getBinaryStream(itemBinaryData.id);
|
||||
} else {
|
||||
uploadData = Buffer.from(itemBinaryData.data, BINARY_ENCODING);
|
||||
}
|
||||
|
||||
const formData = {
|
||||
...body,
|
||||
[propertyName]: {
|
||||
value: dataBuffer,
|
||||
value: uploadData,
|
||||
options: {
|
||||
filename,
|
||||
contentType: itemBinaryData.mimeType,
|
||||
|
@ -2011,20 +2018,16 @@ export class Telegram implements INodeType {
|
|||
encoding: null,
|
||||
uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`,
|
||||
resolveWithFullResponse: true,
|
||||
useStream: true,
|
||||
},
|
||||
);
|
||||
|
||||
const fileName = filePath.split('/').pop();
|
||||
const data = await this.helpers.prepareBinaryData(
|
||||
Buffer.from(file.body as string),
|
||||
fileName,
|
||||
);
|
||||
const data = await this.helpers.prepareBinaryData(file.body, fileName);
|
||||
|
||||
returnData.push({
|
||||
json: responseData,
|
||||
binary: {
|
||||
data,
|
||||
},
|
||||
binary: { data },
|
||||
pairedItem: { item: i },
|
||||
});
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue