From cc7d6a1f37f8dfd781e84739391b18ecbffd6107 Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Fri, 23 Jun 2023 15:37:05 +0100 Subject: [PATCH 1/2] Add support setting the filename --- .../nodes/Matrix/GenericFunctions.ts | 11 +++++++-- .../nodes/Matrix/MediaDescription.ts | 24 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index a01b846934e68..e20868dafe897 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -10,6 +10,7 @@ import type { import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { v4 as uuid } from 'uuid'; +import { add } from 'lodash'; export async function matrixApiRequest( this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, @@ -189,6 +190,7 @@ export async function handleMatrixCall( const roomId = this.getNodeParameter('roomId', index) as string; const mediaType = this.getNodeParameter('mediaType', index) as string; const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index); + const additionalFields = this.getNodeParameter('additionalFields', index); let body; const qs: IDataObject = {}; @@ -197,7 +199,12 @@ export async function handleMatrixCall( const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName); body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName); - qs.filename = fileName; + if (additionalFields.fileName) { + qs.filename = additionalFields.fileName as string; + } else { + qs.filename = fileName; + } + headers['Content-Type'] = mimeType; headers.accept = 'application/json,text/*;q=0.99'; @@ -216,7 +223,7 @@ export async function handleMatrixCall( body = { msgtype: `m.${mediaType}`, - body: fileName, + body: qs.filename, url: uploadRequestResult.content_uri, }; const messageId = uuid(); diff --git a/packages/nodes-base/nodes/Matrix/MediaDescription.ts b/packages/nodes-base/nodes/Matrix/MediaDescription.ts index 22af3a068b974..38e78557a2b25 100644 --- a/packages/nodes-base/nodes/Matrix/MediaDescription.ts +++ b/packages/nodes-base/nodes/Matrix/MediaDescription.ts @@ -81,8 +81,30 @@ export const mediaFields: INodeProperties[] = [ description: 'Image media type', }, ], - description: 'Name of the uploaded file', + description: 'Type of file being uploaded', placeholder: 'mxc://matrix.org/uploaded-media-uri', required: true, }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + default: {}, + displayOptions: { + show: { + resource: ['media'], + operation: ['upload'], + }, + }, + options: [ + { + displayName: 'File Name', + name: 'fileName', + type: 'string', + default: '', + description: 'Name of the file being uploaded', + }, + ], + }, ]; From ca19a892ba32015a09730834db0bcd13383d6a5f Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Fri, 23 Jun 2023 15:38:13 +0100 Subject: [PATCH 2/2] Removed import that appeared --- packages/nodes-base/nodes/Matrix/GenericFunctions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index e20868dafe897..eebe1aebfe65e 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -10,7 +10,6 @@ import type { import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { v4 as uuid } from 'uuid'; -import { add } from 'lodash'; export async function matrixApiRequest( this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,