From 0760c5f64cec19a8d66f67cfaad52428513cacf5 Mon Sep 17 00:00:00 2001 From: m004 <38407173+m004@users.noreply.github.com> Date: Thu, 20 Mar 2025 17:16:11 +0100 Subject: [PATCH] Add authenticated media parameter to getMediaConfig (#4762) * feat(client): Add authenticated media parameter to getMediaConfig * test(client): add tests for mediaconfig --------- Co-authored-by: Maurizio --- spec/integ/matrix-client-methods.spec.ts | 24 ++++++++++++++++++++++++ src/client.ts | 13 ++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index a28ec25d2..1964cbe13 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -157,6 +157,30 @@ describe("MatrixClient", function () { }); }); + describe("mediaConfig", function () { + it("should get media config on unauthenticated media call", async () => { + httpBackend.when("GET", "/_matrix/media/v3/config").respond(200, '{"m.upload.size": 50000000}', true); + + const prom = client.getMediaConfig(); + + httpBackend.flushAllExpected(); + + expect((await prom)["m.upload.size"]).toEqual(50000000); + }); + + it("should get media config on authenticated media call", async () => { + httpBackend + .when("GET", "/_matrix/client/v1/media/config") + .respond(200, '{"m.upload.size": 50000000}', true); + + const prom = client.getMediaConfig(true); + + httpBackend.flushAllExpected(); + + expect((await prom)["m.upload.size"]).toEqual(50000000); + }); + }); + describe("joinRoom", function () { it("should no-op given the ID of a room you've already joined", async () => { const roomId = "!foo:bar"; diff --git a/src/client.ts b/src/client.ts index e74969dae..61828a44b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2069,11 +2069,18 @@ export class MatrixClient extends TypedEventEmitter { - return this.http.authedRequest(Method.Get, "/config", undefined, undefined, { - prefix: MediaPrefix.V3, + public getMediaConfig(useAuthenticatedMedia: boolean = false): Promise { + const path = useAuthenticatedMedia ? "/media/config" : "/config"; + return this.http.authedRequest(Method.Get, path, undefined, undefined, { + prefix: useAuthenticatedMedia ? ClientPrefix.V1 : MediaPrefix.V3, }); }