Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new authenticated endpoints in MediaProxy #506

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/506.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the new authenticated endpoints in MediaProxy.
7 changes: 6 additions & 1 deletion src/components/media-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('^([^/]+)/(.+)$'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume we have tests that cover this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual ones, I'm afraid – our tests never get deep enough to hit onMediaRequest.

I can pull this out into a module and test it there.

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}`,
Expand Down
Loading