From 661ba76763c412d0d400a8b5ba80ab646e8dc492 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 13 Jun 2024 11:03:25 -0600 Subject: [PATCH] Use stable endpoints for MSC3916 (#4239) * Use stable endpoints for MSC3916 * appease the linter --- README.md | 2 +- spec/unit/content-repo.spec.ts | 10 ++++------ src/content-repo.ts | 8 +++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f95833327..24b2334a8 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Object.keys(client.store.rooms).forEach((roomId) => { ## 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 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 `` elements and similar. diff --git a/spec/unit/content-repo.spec.ts b/spec/unit/content-repo.spec.ts index e0f0b5e0c..23f504c1e 100644 --- a/spec/unit/content-repo.spec.ts +++ b/spec/unit/content-repo.spec.ts @@ -80,24 +80,22 @@ describe("ContentRepo", function () { it("should return an authenticated URL when requested", function () { const mxcUri = "mxc://server.name/resourceid"; expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, true, true)).toEqual( - baseUrl + - "/_matrix/client/unstable/org.matrix.msc3916/media/download/server.name/resourceid?allow_redirect=true", + baseUrl + "/_matrix/client/v1/media/download/server.name/resourceid?allow_redirect=true", ); expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, true, true)).toEqual( 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 () { const mxcUri = "mxc://server.name/resourceid"; expect(getHttpUriForMxc(baseUrl, mxcUri, undefined, undefined, undefined, undefined, false, true)).toEqual( - baseUrl + - "/_matrix/client/unstable/org.matrix.msc3916/media/download/server.name/resourceid?allow_redirect=true", + baseUrl + "/_matrix/client/v1/media/download/server.name/resourceid?allow_redirect=true", ); expect(getHttpUriForMxc(baseUrl, mxcUri, 64, 64, "scale", undefined, false, true)).toEqual( 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", ); }); }); diff --git a/src/content-repo.ts b/src/content-repo.ts index eaa119f97..b127f6d2b 100644 --- a/src/content-repo.ts +++ b/src/content-repo.ts @@ -62,7 +62,7 @@ export function getHttpUriForMxc( if (useAuthentication) { 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 // callers, hopefully. } @@ -70,8 +70,7 @@ export function getHttpUriForMxc( let serverAndMediaId = mxc.slice(6); // strips mxc:// let prefix: string; if (useAuthentication) { - // TODO: Use stable once available (requires FCP on MSC3916). - prefix = "/_matrix/client/unstable/org.matrix.msc3916/media/download/"; + prefix = "/_matrix/client/v1/media/download/"; } else { prefix = "/_matrix/media/v3/download/"; } @@ -90,8 +89,7 @@ export function getHttpUriForMxc( // these are thumbnailing params so they probably want the // thumbnailing API... if (useAuthentication) { - // TODO: Use stable once available (requires FCP on MSC3916). - prefix = "/_matrix/client/unstable/org.matrix.msc3916/media/thumbnail/"; + prefix = "/_matrix/client/v1/media/thumbnail/"; } else { prefix = "/_matrix/media/v3/thumbnail/"; }