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

Use stable endpoints for MSC3916 (#4239)

* Use stable endpoints for MSC3916

* appease the linter
This commit is contained in:
Travis Ralston
2024-06-13 11:03:25 -06:00
committed by GitHub
parent 4cb851c51a
commit 661ba76763
3 changed files with 8 additions and 12 deletions

View File

@ -95,7 +95,7 @@ Object.keys(client.store.rooms).forEach((roomId) => {
## Authenticated media ## Authenticated media
Servers supporting [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916) will require clients, like Servers supporting [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916) (Matrix 1.11) will require clients, like
yours, to include an `Authorization` header when `/download`ing or `/thumbnail`ing media. For NodeJS environments this yours, to include an `Authorization` header when `/download`ing or `/thumbnail`ing media. For NodeJS environments this
may be as easy as the following code snippet, though web browsers may need to use [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) may be as easy as the following code snippet, though web browsers may need to use [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
to append the header when using the endpoints in `<img />` elements and similar. to append the header when using the endpoints in `<img />` elements and similar.

View File

@ -80,24 +80,22 @@ describe("ContentRepo", function () {
it("should return an authenticated URL when requested", function () { it("should return an authenticated URL when requested", function () {
const mxcUri = "mxc://server.name/resourceid"; const mxcUri = "mxc://server.name/resourceid";
expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, true, true)).toEqual( expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, true, true)).toEqual(
baseUrl + baseUrl + "/_matrix/client/v1/media/download/server.name/resourceid?allow_redirect=true",
"/_matrix/client/unstable/org.matrix.msc3916/media/download/server.name/resourceid?allow_redirect=true",
); );
expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, true, true)).toEqual( expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, true, true)).toEqual(
baseUrl + baseUrl +
"/_matrix/client/unstable/org.matrix.msc3916/media/thumbnail/server.name/resourceid?width=64&height=64&method=scale&allow_redirect=true", "/_matrix/client/v1/media/thumbnail/server.name/resourceid?width=64&height=64&method=scale&allow_redirect=true",
); );
}); });
it("should force-enable allow_redirects when useAuthentication is set true", function () { it("should force-enable allow_redirects when useAuthentication is set true", function () {
const mxcUri = "mxc://server.name/resourceid"; const mxcUri = "mxc://server.name/resourceid";
expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, false, true)).toEqual( expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, false, true)).toEqual(
baseUrl + baseUrl + "/_matrix/client/v1/media/download/server.name/resourceid?allow_redirect=true",
"/_matrix/client/unstable/org.matrix.msc3916/media/download/server.name/resourceid?allow_redirect=true",
); );
expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, false, true)).toEqual( expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, false, true)).toEqual(
baseUrl + baseUrl +
"/_matrix/client/unstable/org.matrix.msc3916/media/thumbnail/server.name/resourceid?width=64&height=64&method=scale&allow_redirect=true", "/_matrix/client/v1/media/thumbnail/server.name/resourceid?width=64&height=64&method=scale&allow_redirect=true",
); );
}); });
}); });

View File

@ -62,7 +62,7 @@ export function getHttpUriForMxc(
if (useAuthentication) { if (useAuthentication) {
allowRedirects = true; // per docs (MSC3916 always expects redirects) allowRedirects = true; // per docs (MSC3916 always expects redirects)
// Dev note: MSC3916 (as of writing) removes `allow_redirect` entirely, but // Dev note: MSC3916 removes `allow_redirect` entirely, but
// for explicitness we set it here. This makes it slightly more obvious to // for explicitness we set it here. This makes it slightly more obvious to
// callers, hopefully. // callers, hopefully.
} }
@ -70,8 +70,7 @@ export function getHttpUriForMxc(
let serverAndMediaId = mxc.slice(6); // strips mxc:// let serverAndMediaId = mxc.slice(6); // strips mxc://
let prefix: string; let prefix: string;
if (useAuthentication) { if (useAuthentication) {
// TODO: Use stable once available (requires FCP on MSC3916). prefix = "/_matrix/client/v1/media/download/";
prefix = "/_matrix/client/unstable/org.matrix.msc3916/media/download/";
} else { } else {
prefix = "/_matrix/media/v3/download/"; prefix = "/_matrix/media/v3/download/";
} }
@ -90,8 +89,7 @@ export function getHttpUriForMxc(
// these are thumbnailing params so they probably want the // these are thumbnailing params so they probably want the
// thumbnailing API... // thumbnailing API...
if (useAuthentication) { if (useAuthentication) {
// TODO: Use stable once available (requires FCP on MSC3916). prefix = "/_matrix/client/v1/media/thumbnail/";
prefix = "/_matrix/client/unstable/org.matrix.msc3916/media/thumbnail/";
} else { } else {
prefix = "/_matrix/media/v3/thumbnail/"; prefix = "/_matrix/media/v3/thumbnail/";
} }