mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -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 {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
@ -1962,7 +1963,6 @@ export class Telegram implements INodeType {
|
||||||
if (binaryData) {
|
if (binaryData) {
|
||||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
|
||||||
const itemBinaryData = items[i].binary![binaryPropertyName];
|
const itemBinaryData = items[i].binary![binaryPropertyName];
|
||||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
|
||||||
const propertyName = getPropertyName(operation);
|
const propertyName = getPropertyName(operation);
|
||||||
const fileName = this.getNodeParameter('additionalFields.fileName', 0, '') as string;
|
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';
|
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 = {
|
const formData = {
|
||||||
...body,
|
...body,
|
||||||
[propertyName]: {
|
[propertyName]: {
|
||||||
value: dataBuffer,
|
value: uploadData,
|
||||||
options: {
|
options: {
|
||||||
filename,
|
filename,
|
||||||
contentType: itemBinaryData.mimeType,
|
contentType: itemBinaryData.mimeType,
|
||||||
|
@ -2011,20 +2018,16 @@ export class Telegram implements INodeType {
|
||||||
encoding: null,
|
encoding: null,
|
||||||
uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`,
|
uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`,
|
||||||
resolveWithFullResponse: true,
|
resolveWithFullResponse: true,
|
||||||
|
useStream: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const fileName = filePath.split('/').pop();
|
const fileName = filePath.split('/').pop();
|
||||||
const data = await this.helpers.prepareBinaryData(
|
const data = await this.helpers.prepareBinaryData(file.body, fileName);
|
||||||
Buffer.from(file.body as string),
|
|
||||||
fileName,
|
|
||||||
);
|
|
||||||
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
json: responseData,
|
json: responseData,
|
||||||
binary: {
|
binary: { data },
|
||||||
data,
|
|
||||||
},
|
|
||||||
pairedItem: { item: i },
|
pairedItem: { item: i },
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue