From 22aca9546f8a231af43bb158618b9bbc429188ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Thu, 5 Sep 2024 11:05:00 +0200 Subject: [PATCH] Use the new authenticated endpoints in MediaProxy --- src/components/media-proxy.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/media-proxy.ts b/src/components/media-proxy.ts index 3a991364..24faa89d 100644 --- a/src/components/media-proxy.ts +++ b/src/components/media-proxy.ts @@ -147,7 +147,12 @@ export class MediaProxy { } // Cache from this point onwards. // Extract the media from the event. - const url = this.matrixClient.mxcToHttp('mxc://' + metadata.mxc); + const mxcMatch = metadata.mxc.match(new RegExp('^([^/]+)/(.+)$')); + if (!mxcMatch) { + throw new ApiError('Invalid MXC URI', ErrCode.BadValue); + } + const [, serverName, mediaId ] = mxcMatch; + const url = `${this.matrixClient.homeserverUrl}/_matrix/client/v1/media/download/${serverName}/${mediaId}`; get(url, { headers: { 'Authorization': `Bearer ${this.matrixClient.accessToken}`,