Skip to content

Commit 0760c5f

Browse files
m004Maurizio
andauthored
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>
1 parent e2bdb2f commit 0760c5f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

spec/integ/matrix-client-methods.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ describe("MatrixClient", function () {
157157
});
158158
});
159159

160+
describe("mediaConfig", function () {
161+
it("should get media config on unauthenticated media call", async () => {
162+
httpBackend.when("GET", "/_matrix/media/v3/config").respond(200, '{"m.upload.size": 50000000}', true);
163+
164+
const prom = client.getMediaConfig();
165+
166+
httpBackend.flushAllExpected();
167+
168+
expect((await prom)["m.upload.size"]).toEqual(50000000);
169+
});
170+
171+
it("should get media config on authenticated media call", async () => {
172+
httpBackend
173+
.when("GET", "/_matrix/client/v1/media/config")
174+
.respond(200, '{"m.upload.size": 50000000}', true);
175+
176+
const prom = client.getMediaConfig(true);
177+
178+
httpBackend.flushAllExpected();
179+
180+
expect((await prom)["m.upload.size"]).toEqual(50000000);
181+
});
182+
});
183+
160184
describe("joinRoom", function () {
161185
it("should no-op given the ID of a room you've already joined", async () => {
162186
const roomId = "!foo:bar";

src/client.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,11 +2069,18 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
20692069

20702070
/**
20712071
* Get the config for the media repository.
2072+
*
2073+
* @param useAuthenticatedMedia - If true, the caller supports authenticated
2074+
* media and wants an authentication-required URL. Note that server support
2075+
* for authenticated media will *not* be checked - it is the caller's responsibility
2076+
* to do so before calling this function.
2077+
*
20722078
* @returns Promise which resolves with an object containing the config.
20732079
*/
2074-
public getMediaConfig(): Promise<IMediaConfig> {
2075-
return this.http.authedRequest(Method.Get, "/config", undefined, undefined, {
2076-
prefix: MediaPrefix.V3,
2080+
public getMediaConfig(useAuthenticatedMedia: boolean = false): Promise<IMediaConfig> {
2081+
const path = useAuthenticatedMedia ? "/media/config" : "/config";
2082+
return this.http.authedRequest(Method.Get, path, undefined, undefined, {
2083+
prefix: useAuthenticatedMedia ? ClientPrefix.V1 : MediaPrefix.V3,
20772084
});
20782085
}
20792086

0 commit comments

Comments
 (0)