refactor: Unify binary-data assertion across all nodes (no-changelog) (#5624)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-03-06 17:33:32 +01:00
committed by GitHub
parent 01a2160b3b
commit 5eb0d52459
69 changed files with 411 additions and 1573 deletions

View File

@@ -1,10 +1,14 @@
import type { OptionsWithUri } from 'request';
import type { IDataObject, JsonObject } from 'n8n-workflow';
import type {
IDataObject,
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
import type { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
import { v4 as uuid } from 'uuid';
export async function matrixApiRequest(
@@ -190,25 +194,11 @@ export async function handleMatrixCall(
const qs: IDataObject = {};
const headers: IDataObject = {};
if (
item.binary === undefined ||
//@ts-ignore
item.binary[binaryPropertyName] === undefined
) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
// @ts-ignore
qs.filename = item.binary[binaryPropertyName].fileName;
//@ts-ignore
const filename = item.binary[binaryPropertyName].fileName;
const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
//@ts-ignore
headers['Content-Type'] = item.binary[binaryPropertyName].mimeType;
qs.filename = fileName;
headers['Content-Type'] = mimeType;
headers.accept = 'application/json,text/*;q=0.99';
const uploadRequestResult = await matrixApiRequest.call(
@@ -226,7 +216,7 @@ export async function handleMatrixCall(
body = {
msgtype: `m.${mediaType}`,
body: filename,
body: fileName,
url: uploadRequestResult.content_uri,
};
const messageId = uuid();