Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Enable redirected media by default #12142

Merged
merged 11 commits into from
Feb 11, 2024
2 changes: 1 addition & 1 deletion playwright/e2e/timeline/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const expectAvatar = async (cli: Client, e: Locator, avatarUrl: string): Promise
const url = await cli.evaluate(
(client, { avatarUrl, size, resizeMethod }) => {
// eslint-disable-next-line no-restricted-properties
return client.mxcUrlToHttp(avatarUrl, size, size, resizeMethod);
return client.mxcUrlToHttp(avatarUrl, size, size, resizeMethod, false, true);
},
{ avatarUrl, size, resizeMethod: AVATAR_RESIZE_METHOD },
);
Expand Down
8 changes: 4 additions & 4 deletions src/customisations/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Media {
*/
public get srcHttp(): string | null {
// eslint-disable-next-line no-restricted-properties
return this.client.mxcUrlToHttp(this.srcMxc) || null;
return this.client.mxcUrlToHttp(this.srcMxc, undefined, undefined, undefined, false, true) || null;
}

/**
Expand All @@ -90,7 +90,7 @@ export class Media {
public get thumbnailHttp(): string | null {
if (!this.hasThumbnail) return null;
// eslint-disable-next-line no-restricted-properties
return this.client.mxcUrlToHttp(this.thumbnailMxc!);
return this.client.mxcUrlToHttp(this.thumbnailMxc!, undefined, undefined, undefined, false, true);
}

/**
Expand All @@ -107,7 +107,7 @@ export class Media {
width = Math.floor(width * window.devicePixelRatio);
height = Math.floor(height * window.devicePixelRatio);
// eslint-disable-next-line no-restricted-properties
return this.client.mxcUrlToHttp(this.thumbnailMxc!, width, height, mode);
return this.client.mxcUrlToHttp(this.thumbnailMxc!, width, height, mode, false, true);
}

/**
Expand All @@ -122,7 +122,7 @@ export class Media {
width = Math.floor(width * window.devicePixelRatio);
height = Math.floor(height * window.devicePixelRatio);
// eslint-disable-next-line no-restricted-properties
return this.client.mxcUrlToHttp(this.srcMxc, width, height, mode);
return this.client.mxcUrlToHttp(this.srcMxc, width, height, mode, false, true);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions test/components/views/messages/MImageBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("<MImageBody/>", () => {
},
}),
});
const url = "https://server/_matrix/media/v3/download/server/encrypted-image";
const url = "https://server/_matrix/media/v3/download/server/encrypted-image?allow_redirect=false";
// eslint-disable-next-line no-restricted-properties
cli.mxcUrlToHttp.mockImplementation(
(mxcUrl: string, width?: number, height?: number, resizeMethod?: string, allowDirectLinks?: boolean) => {
Expand Down Expand Up @@ -180,8 +180,9 @@ describe("<MImageBody/>", () => {
});

it("should fall back to /download/ if /thumbnail/ fails", async () => {
const thumbUrl = "https://server/_matrix/media/v3/thumbnail/server/image?width=800&height=600&method=scale";
const downloadUrl = "https://server/_matrix/media/v3/download/server/image";
const thumbUrl =
"https://server/_matrix/media/v3/thumbnail/server/image?width=800&height=600&method=scale&allow_redirect=false";
const downloadUrl = "https://server/_matrix/media/v3/download/server/image?allow_redirect=false";

const event = new MatrixEvent({
room_id: "!room:server",
Expand Down Expand Up @@ -228,7 +229,7 @@ describe("<MImageBody/>", () => {
mocked(global.URL.createObjectURL).mockReturnValue("blob:generated-thumb");

fetchMock.getOnce(
"https://server/_matrix/media/v3/download/server/image",
"https://server/_matrix/media/v3/download/server/image?allow_redirect=false",
{
body: fs.readFileSync(path.resolve(__dirname, "..", "..", "..", "images", "animated-logo.webp")),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`<MImageBody/> should generate a thumbnail if one isn't included for ani
class="mx_MImageBody"
>
<a
href="https://server/_matrix/media/v3/download/server/image"
href="https://server/_matrix/media/v3/download/server/image?allow_redirect=false"
>
<div
class="mx_MImageBody_thumbnail_container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`MVideoBody should show poster for encrypted media before downloading it
class="mx_MVideoBody"
controls=""
controlslist="nodownload"
poster="https://server/_matrix/media/v3/download/server/encrypted-poster"
poster="https://server/_matrix/media/v3/download/server/encrypted-poster?allow_redirect=false"
preload="none"
title="alt for a test video"
/>
Expand Down
Loading