fix: preserve homeserver port when creating thumbnail URIs

This commit is contained in:
Sorunome 2021-07-11 12:52:13 +02:00
parent cd5131daa5
commit 44b7c96d73
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 24 additions and 0 deletions

View File

@ -46,6 +46,7 @@ extension MxcUriExtension on Uri {
scheme: matrix.homeserver.scheme, scheme: matrix.homeserver.scheme,
host: matrix.homeserver.host, host: matrix.homeserver.host,
path: '/_matrix/media/r0/thumbnail/$host$path', path: '/_matrix/media/r0/thumbnail/$host$path',
port: matrix.homeserver.port,
queryParameters: { queryParameters: {
if (width != null) 'width': width.round().toString(), if (width != null) 'width': width.round().toString(),
if (height != null) 'height': height.round().toString(), if (height != null) 'height': height.round().toString(),

View File

@ -50,5 +50,28 @@ void main() {
.toString(), .toString(),
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale&animated=true'); '${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale&animated=true');
}); });
test('other port', () async {
final client = Client('testclient', httpClient: FakeMatrixApi());
await client.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
client.homeserver = Uri.parse('https://fakeserver.notexisting:1337');
final mxc = 'mxc://exampleserver.abc/abcdefghijklmn';
final content = Uri.parse(mxc);
expect(content.isScheme('mxc'), true);
expect(content.getDownloadLink(client).toString(),
'${client.homeserver.toString()}/_matrix/media/r0/download/exampleserver.abc/abcdefghijklmn');
expect(content.getThumbnail(client, width: 50, height: 50).toString(),
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=crop&animated=false');
expect(
content
.getThumbnail(client,
width: 50,
height: 50,
method: ThumbnailMethod.scale,
animated: true)
.toString(),
'https://fakeserver.notexisting:1337/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale&animated=true');
});
}); });
} }