From 4823babb29e8d2c2f65b775e72210aac7a2175c5 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:09:38 -0300 Subject: Add Matrix::Client::MediaStore class This is to wrap all the endpoints pointing to the media store. --- lib/Matrix/Client/MediaStore.rakumod | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/Matrix/Client/MediaStore.rakumod (limited to 'lib/Matrix/Client/MediaStore.rakumod') diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod new file mode 100644 index 0000000..34fbda3 --- /dev/null +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -0,0 +1,70 @@ +use JSON::Fast; +use Matrix::Client::Requester; +use Matrix::Client::Exception; +use URI::Escape; + +unit class Matrix::Client::MediaStore does Matrix::Client::Requester; + +class Matrix::Client::MediaStore::File { + has Str $.content-type; + has Str $.content-disposition; + has Buf $.content; +} + +submethod TWEAK { + # Different client endpoint for media + $!client-endpoint = "/_matrix/media/r0"; +} + +# https://matrix.deprecated.org/_matrix/media/r0/thumbnail/matrix.org/TKTUVTAazFocrTjezhiXZiIe?width=25&height=25&method=crop +method parse-mxc(Str $uri) { + if $uri ~~ m/"mxc://" $ = [.*] "/" $ = [ .* ]/ { + return { + server-name => $, + media-id => $ + } + } + + X::Matrix::MXCParse.new(:$uri).throw; +} + +#| POST - /_matrix/media/r0/upload +method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "image/png" --> Str) { + my $buf = slurp $path, :bin; + my $fn = $filename ?? $filename !! $path.basename; + + # The filename is passed on a query param. + my $endpoint = "/upload?filename=" ~ uri-escape($fn); + + + my $res = $.post-bin( + $endpoint, $buf, + :$content-type, + ); + + my $data = from-json($res.content); + $data // ""; +} + +# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +multi method download(Str $mxc-uri, :$allow-remote = True) { + my $mxc = self.parse-mxc($mxc-uri); + + samewith($mxc, $mxc, :$allow-remote) +} + +# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { + my $response = $.get( + "/download/{$server-name}/{$media-id}", + allow_remote => $allow-remote.Str.lc + ); + + my %headers = $response.header.hash(); + + Matrix::Client::MediaStore::File.new( + content-type => %headers.head, + content-disposition => %headers.head, + content => $response.content + ) +} -- cgit v1.2.3-70-g09d2 From 4b01ebdcaa8d7df0ec34c758ae9f3b8ec32fdcd0 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:25:25 -0300 Subject: Fix missing multi methods on the endpoints TODO generator --- endpoints.md | 16 +++++++++------- lib/Matrix/Client/MediaStore.rakumod | 4 ++-- scripts/load-docs.p6 | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'lib/Matrix/Client/MediaStore.rakumod') diff --git a/endpoints.md b/endpoints.md index 2ddf2c3..c77b6c4 100644 --- a/endpoints.md +++ b/endpoints.md @@ -30,7 +30,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media - [ ] GET - /_matrix/media/r0/config -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url - [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} @@ -104,9 +104,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members - [ ] GET - /_matrix/client/r0/rooms/{roomId}/members - [X] GET - /_matrix/client/r0/rooms/{roomId}/messages -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state +- [X] GET - /_matrix/client/r0/rooms/{roomId}/state - [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -- [ ] GET - /_matrix/client/r0/sync +- [X] GET - /_matrix/client/r0/sync - [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} - [ ] POST - /_matrix/client/r0/user/{userId}/filter @@ -136,7 +136,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Session management - [ ] GET - /_matrix/client/r0/login -- [ ] POST - /_matrix/client/r0/login +- [X] POST - /_matrix/client/r0/login - [X] POST - /_matrix/client/r0/logout - [ ] POST - /_matrix/client/r0/logout/all @@ -151,18 +151,20 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/register/available - [ ] GET - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +- [X] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - [ ] POST - /_matrix/client/r0/account/3pid +- [ ] POST - /_matrix/client/r0/account/3pid/bind - [ ] POST - /_matrix/client/r0/account/3pid/delete +- [ ] POST - /_matrix/client/r0/account/3pid/unbind - [ ] POST - /_matrix/client/r0/account/deactivate - [ ] POST - /_matrix/client/r0/account/password - [X] POST - /_matrix/client/r0/register - [ ] POST - /_matrix/client/r0/user_directory/search -- [ ] PUT - /_matrix/client/r0/profile/{userId}/avatar_url +- [X] PUT - /_matrix/client/r0/profile/{userId}/avatar_url - [X] PUT - /_matrix/client/r0/profile/{userId}/displayname - [ ] PUT - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +- [X] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} ## VOIP diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 34fbda3..7086083 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -46,14 +46,14 @@ method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "imag $data // ""; } -# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} multi method download(Str $mxc-uri, :$allow-remote = True) { my $mxc = self.parse-mxc($mxc-uri); samewith($mxc, $mxc, :$allow-remote) } -# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { my $response = $.get( "/download/{$server-name}/{$media-id}", diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index b20dd86..87ef0d4 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -34,8 +34,9 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; - my $implemented-methods = (Matrix::Client, Matrix::Client::Room).map(*.^methods) - .flat.map( + my $implemented-methods = ( + Matrix::Client, Matrix::Client::Room, Matrix::Client::MediaStore + ).map(*.^methodsĀ».candidates).flat.map( { quietly try { .WHY.Str } or "" }).grep(/_matrix/).SetHash; -- cgit v1.2.3-70-g09d2 From 80d50c14866f6e58ee57792a383920a7e8a1274a Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:38:12 -0300 Subject: Add media store config method --- lib/Matrix/Client/MediaStore.rakumod | 10 ++++-- lib/Matrix/Response.pm6 | 9 ++++- t/40-response.t | 44 +++++++++++++++-------- t/60-media.t | 69 ++++++++++++++++++++++++------------ 4 files changed, 92 insertions(+), 40 deletions(-) (limited to 'lib/Matrix/Client/MediaStore.rakumod') diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 7086083..7afa9e3 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -1,7 +1,9 @@ use JSON::Fast; +use URI::Escape; + use Matrix::Client::Requester; use Matrix::Client::Exception; -use URI::Escape; +use Matrix::Response; unit class Matrix::Client::MediaStore does Matrix::Client::Requester; @@ -16,7 +18,6 @@ submethod TWEAK { $!client-endpoint = "/_matrix/media/r0"; } -# https://matrix.deprecated.org/_matrix/media/r0/thumbnail/matrix.org/TKTUVTAazFocrTjezhiXZiIe?width=25&height=25&method=crop method parse-mxc(Str $uri) { if $uri ~~ m/"mxc://" $ = [.*] "/" $ = [ .* ]/ { return { @@ -68,3 +69,8 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru content => $response.content ) } + +method config(--> Matrix::Response::MediaStore::Config) { + my $response = $.get("/config"); + Matrix::Response::MediaStore::Config.new(from-json($response.content)) +} diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index 268be84..ec93cf3 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -123,7 +123,6 @@ class Tag { } } - class Matrix::Response::Device { has Str $.device-id; has $.display-name; @@ -137,3 +136,11 @@ class Matrix::Response::Device { :last_seen_ts(:$!last-seen-ts)? ) { } } + +class Matrix::Response::MediaStore::Config { + has Int $.upload-size; + + method new(%config) { + self.bless(:upload-size(%config // Int)); + } +} diff --git a/t/40-response.t b/t/40-response.t index cc219b2..8bc3569 100644 --- a/t/40-response.t +++ b/t/40-response.t @@ -2,24 +2,38 @@ use lib 'lib'; use Test; use JSON::Fast; use Matrix::Response; -plan 7; +plan 2; -my $test-file = 'sync.json'; +subtest 'Sync', { + plan 7; + my $test-file = 'sync.json'; + my $data; -unless $test-file.IO.f { - skip-rest 'Missing sync.json to test'; - exit; -} + if $test-file.IO.f { + $data = from-json($test-file.IO.slurp); + lives-ok { Matrix::Response::Sync.new($test-file.IO.slurp) }, 'Sync.new accepts Str'; + lives-ok { Matrix::Response::Sync.new($data) }, 'Sync.new accepts Associative'; -my $data = from-json($test-file.IO.slurp); + my $res = Matrix::Response::Sync.new($data); + can-ok $res, 'joined-rooms', 'can .joined-rooms'; + can-ok $res, 'presence', 'can .presence'; -ok $data; -lives-ok { Matrix::Response::Sync.new($test-file.IO.slurp) }; -lives-ok { Matrix::Response::Sync.new($data) }; + isa-ok $res.joined-rooms, List, '.joined-rooms returns a List'; + isa-ok $res.presence, List, '.presence returns a List'; -my $res = Matrix::Response::Sync.new($data); -can-ok $res, 'joined-rooms'; -can-ok $res, 'presence'; + } else { + skip 'Missing sync.json to test', 7; + } -isa-ok $res.joined-rooms, List; -isa-ok $res.presence, List; +}; + +subtest 'MediaStore', { + plan 4; + my %config = 'm.upload.size' => 5000; + my $config-response = Matrix::Response::MediaStore::Config.new(|%config); + + isa-ok $config-response, Matrix::Response::MediaStore::Config; + can-ok $config-response, 'upload-size'; + isa-ok $config-response.upload-size, Int; + is $config-response.upload-size, %config, 'correct upload size'; +}; diff --git a/t/60-media.t b/t/60-media.t index 602b0fc..5601d8a 100644 --- a/t/60-media.t +++ b/t/60-media.t @@ -3,39 +3,40 @@ use Test; use Matrix::Client::MediaStore; use Matrix::Client::Exception; -plan 6; - my $path = $*TMPDIR.add('matrix-client-test'); LEAVE { unlink $path; } $path.spurt("") unless $path.f; -# Mock the post-bin method of Matrix::Client::Requester. -my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { - has %.called-with; - method post-bin(Str $path, Buf $buf, :$content-type) { - %.called-with = $path; - %.called-with = $buf; - %.called-with = $content-type; +subtest 'Upload', { + plan 5; + # Mock the post-bin method of Matrix::Client::Requester. + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + has %.called-with; + method post-bin(Str $path, Buf $buf, :$content-type) { + %.called-with = $path; + %.called-with = $buf; + %.called-with = $content-type; - class { method content { '{"content_uri": "bla" }' } } + class { method content { '{"content_uri": "bla" }' } } + } } -} -$media.upload($path, "something"); -is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; + $media.upload($path, "something"); + is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; -$media.upload($path, "something with spaces"); -is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; + $media.upload($path, "something with spaces"); + is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; -$media.upload($path); -is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; -is $media.called-with, 'image/png', "By default use `image/png` MIME"; + $media.upload($path); + is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; + is $media.called-with, 'image/png', "By default use `image/png` MIME"; -$media.upload($path, content-type => 'application/pdf'); -is $media.called-with, 'application/pdf', "Can change the content type"; + $media.upload($path, content-type => 'application/pdf'); + is $media.called-with, 'application/pdf', "Can change the content type"; +} -subtest { +subtest 'mxc parsing', { plan 2; my $media = Matrix::Client::MediaStore.new(:home-server("1234")); is $media.parse-mxc("mxc://matrix.org/123456.pdf"), { @@ -46,4 +47,28 @@ subtest { $media.parse-mxc("http://matrix.org/123456.pdf") }, X::Matrix::MXCParse, 'Dies with HTTP URI'; -}, 'mxc parsing'; +}; + +subtest 'config', { + # Mock the post-bin method of Matrix::Client::Requester. + plan 5; + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{"m.upload.size": 5000 }' } } + } + } + + isa-ok $media.config, Matrix::Response::MediaStore::Config, 'Can load Associative'; + is $media.config.upload-size, 5000, 'correct upload size'; + + my $empty-media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{}' } } + } + } + + isa-ok $empty-media.config, Matrix::Response::MediaStore::Config, 'Can load empty configuration'; + is $empty-media.config.upload-size, Int, 'Unknown upload-size'; + nok $empty-media.config.upload-size.defined, 'upload-size not defined'; + +} -- cgit v1.2.3-70-g09d2 From ab2a237e5cff43f9b8cd806b7e9e271ffb01b461 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:51:23 -0300 Subject: Update endpoints script. Show the total of endpoints implemented at the end --- endpoints.md | 12 ++++++++++-- lib/Matrix/Client/MediaStore.rakumod | 1 + scripts/load-docs.p6 | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/Matrix/Client/MediaStore.rakumod') diff --git a/endpoints.md b/endpoints.md index c77b6c4..f47105b 100644 --- a/endpoints.md +++ b/endpoints.md @@ -29,7 +29,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media -- [ ] GET - /_matrix/media/r0/config +- [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url @@ -52,6 +52,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/pushers - [ ] GET - /_matrix/client/r0/pushrules/ - [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled - [ ] POST - /_matrix/client/r0/pushers/set - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions @@ -73,6 +75,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} - [X] GET - /_matrix/client/r0/directory/room/{roomAlias} +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/aliases - [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery @@ -115,7 +118,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [ ] PUT - /_matrix/client/r0/rooms/{roomId}/typing/{userId} -## Room ugprades +## Room upgrades - [ ] POST - /_matrix/client/r0/rooms/{roomId}/upgrade @@ -170,3 +173,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/voip/turnServer + +# Endpoint completion + +0.378641% - (39/103) + diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 7afa9e3..cb59626 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -70,6 +70,7 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); Matrix::Response::MediaStore::Config.new(from-json($response.content)) diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index 87ef0d4..2392a3a 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -34,6 +34,8 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; + my $total = 0; + my $completed = 0; my $implemented-methods = ( Matrix::Client, Matrix::Client::Room, Matrix::Client::MediaStore ).map(*.^methodsĀ».candidates).flat.map( @@ -58,6 +60,9 @@ sub MAIN(:$spec?) { for $methods.Seq.sort -> $m { my Str $method = $m.trim; my $checked = $implemented-methods{$m} ?? "X" !! " "; + $completed++ if $implemented-methods{$m}; + $total++; + if $spec { $method = $m.subst(/unstable/, $spec) } @@ -65,4 +70,11 @@ sub MAIN(:$spec?) { } say ""; } + + say qq:to/EOF/; + + # Endpoint completion + + {$completed/$total}% - ($completed/$total) + EOF } -- cgit v1.2.3-70-g09d2 From d8f623d8093ff8e47d386f86e61deebdac66fc29 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 20:16:15 -0300 Subject: Add thumbnail endpoint --- endpoints.md | 6 ++--- lib/Matrix/Client/MediaStore.rakumod | 49 ++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) (limited to 'lib/Matrix/Client/MediaStore.rakumod') diff --git a/endpoints.md b/endpoints.md index f47105b..ad26ad9 100644 --- a/endpoints.md +++ b/endpoints.md @@ -31,9 +31,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url -- [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} - [X] POST - /_matrix/media/r0/upload ## OpenID @@ -176,5 +176,5 @@ from matrix.org. This will give you an overview about what's implemented in the # Endpoint completion -0.378641% - (39/103) +0.398058% - (41/103) diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index cb59626..9779db2 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -48,16 +48,20 @@ method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "imag } #| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $mxc-uri, :$allow-remote = True) { +multi method download(Str $mxc-uri, :$allow-remote = True, Str :$filename?) { my $mxc = self.parse-mxc($mxc-uri); - samewith($mxc, $mxc, :$allow-remote) + samewith($mxc, $mxc, :$allow-remote, :$filename) } -#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +multi method download(Str $server-name, Str $media-id, + Bool :$allow-remote = True, Str :$filename?) { + my $endpoint = "/download/{$server-name}/{$media-id}"; + + $endpoint ~= "/{$filename}" if $filename.defined; my $response = $.get( - "/download/{$server-name}/{$media-id}", + $endpoint, allow_remote => $allow-remote.Str.lc ); @@ -70,6 +74,41 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $mxc-uri, Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $mxc = self.parse-mxc($mxc-uri); + samewith( + $mxc, $mxc, + $width, $height, + :$method, :$allow-remote + ) +} + +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $server-name, Str $media-id, + Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $endpoint = "/thumbnail/{$server-name}/{$media-id}"; + + my $response = $.get( + $endpoint, + :$height, + :$width, + :$method, + allow_remote => $allow-remote.Str.lc + ); + + my %headers = $response.header.hash(); + + Matrix::Client::MediaStore::File.new( + content-type => %headers.head, + content => $response.content + ) +} + #| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); -- cgit v1.2.3-70-g09d2