1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-30 04:23:07 +03:00

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 <maurizio-noah.abbruzzo-santiago@t-systems.com>
This commit is contained in:
m004
2025-03-20 17:16:11 +01:00
committed by GitHub
parent e2bdb2f057
commit 0760c5f64c
2 changed files with 34 additions and 3 deletions

View File

@ -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";

View File

@ -2069,11 +2069,18 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
/**
* Get the config for the media repository.
*
* @param useAuthenticatedMedia - If true, the caller supports authenticated
* media and wants an authentication-required URL. Note that server support
* for authenticated media will *not* be checked - it is the caller's responsibility
* to do so before calling this function.
*
* @returns Promise which resolves with an object containing the config.
*/
public getMediaConfig(): Promise<IMediaConfig> {
return this.http.authedRequest(Method.Get, "/config", undefined, undefined, {
prefix: MediaPrefix.V3,
public getMediaConfig(useAuthenticatedMedia: boolean = false): Promise<IMediaConfig> {
const path = useAuthenticatedMedia ? "/media/config" : "/config";
return this.http.authedRequest(Method.Get, path, undefined, undefined, {
prefix: useAuthenticatedMedia ? ClientPrefix.V1 : MediaPrefix.V3,
});
}