From ea328e56cdfd1d8d1584e5198707dad982d25be9 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 16 Oct 2020 00:01:07 +0300 Subject: [PATCH] :zap: Add support for specifying Matrix homeserver URL (#1065) --- packages/nodes-base/credentials/MatrixApi.credentials.ts | 6 ++++++ packages/nodes-base/nodes/Matrix/GenericFunctions.ts | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/credentials/MatrixApi.credentials.ts b/packages/nodes-base/credentials/MatrixApi.credentials.ts index b03d954d12..4a03fd7331 100644 --- a/packages/nodes-base/credentials/MatrixApi.credentials.ts +++ b/packages/nodes-base/credentials/MatrixApi.credentials.ts @@ -15,5 +15,11 @@ export class MatrixApi implements ICredentialType { type: 'string' as NodePropertyTypes, default: '', }, + { + displayName: 'Homeserver URL', + name: 'homeserverUrl', + type: 'string' as NodePropertyTypes, + default: 'https://matrix-client.matrix.org', + }, ]; } diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index b798a1c9f5..79efcb89e3 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -36,9 +36,7 @@ export async function matrixApiRequest(this: IExecuteFunctions | IExecuteSingleF }, body, qs: query, - // Override URL when working with media only. All other endpoints use client. - //@ts-ignore - uri: option.hasOwnProperty('overridePrefix') ? `https://matrix.org/_matrix/${option.overridePrefix}/r0${resource}` : `https://matrix.org/_matrix/client/r0${resource}`, + uri: '', json: true, }; options = Object.assign({}, options, option); @@ -56,6 +54,8 @@ export async function matrixApiRequest(this: IExecuteFunctions | IExecuteSingleF if (credentials === undefined) { throw new Error('No credentials got returned!'); } + //@ts-ignore + options.uri = `${credentials.homeserverUrl}/_matrix/${option.overridePrefix || 'client'}/r0${resource}`; options.headers!.Authorization = `Bearer ${credentials.accessToken}`; //@ts-ignore response = await this.helpers.request(options);