diff --git a/spec/unit/content-repo.spec.ts b/spec/unit/content-repo.spec.ts index 91953945ac7..33eeab12d5e 100644 --- a/spec/unit/content-repo.spec.ts +++ b/spec/unit/content-repo.spec.ts @@ -37,6 +37,21 @@ describe("ContentRepo", function () { ); }); + it("should allow redirects when requested on download URLs", function () { + const mxcUri = "mxc://server.name/resourceid"; + expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, false, true)).toEqual( + baseUrl + "/_matrix/media/v3/download/server.name/resourceid?allow_redirect=true", + ); + }); + + it("should allow redirects when requested on thumbnail URLs", function () { + const mxcUri = "mxc://server.name/resourceid"; + expect(getHttpUriForMxc(baseUrl, mxcUri, 32, 32, "scale", false, true)).toEqual( + baseUrl + + "/_matrix/media/v3/thumbnail/server.name/resourceid?width=32&height=32&method=scale&allow_redirect=true", + ); + }); + it("should return the empty string for null input", function () { expect(getHttpUriForMxc(null as any, "")).toEqual(""); }); diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 920bec55804..8f87d6f8cc6 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -55,6 +55,7 @@ import { RuleId, IPushRule, ConditionKind, + getHttpUriForMxc, } from "../../src"; import { supportsMatrixCall } from "../../src/webrtc/call"; import { makeBeaconEvent } from "../test-utils/beacon"; @@ -369,6 +370,21 @@ describe("MatrixClient", function () { client.stopClient(); }); + describe("mxcUrlToHttp", () => { + it("should call getHttpUriForMxc", () => { + const mxc = "mxc://server/example"; + expect(client.mxcUrlToHttp(mxc)).toBe(getHttpUriForMxc(client.baseUrl, mxc)); + expect(client.mxcUrlToHttp(mxc, 32)).toBe(getHttpUriForMxc(client.baseUrl, mxc, 32)); + expect(client.mxcUrlToHttp(mxc, 32, 46)).toBe(getHttpUriForMxc(client.baseUrl, mxc, 32, 46)); + expect(client.mxcUrlToHttp(mxc, 32, 46, "scale")).toBe( + getHttpUriForMxc(client.baseUrl, mxc, 32, 46, "scale"), + ); + expect(client.mxcUrlToHttp(mxc, 32, 46, "scale", false, true)).toBe( + getHttpUriForMxc(client.baseUrl, mxc, 32, 46, "scale", false, true), + ); + }); + }); + describe("timestampToEvent", () => { const roomId = "!room:server.org"; const eventId = "$eventId:example.org"; diff --git a/src/client.ts b/src/client.ts index 3acc0135209..bb294f87e38 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5805,6 +5805,9 @@ export class MatrixClient extends TypedEventEmitter= 0) {