aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2020-09-06 20:16:15 -0300
committerMatias Linares <matiaslina@gmail.com>2020-09-06 20:16:15 -0300
commitd8f623d8093ff8e47d386f86e61deebdac66fc29 (patch)
tree7e422727f343e05306454d4f344ef446ccb254ef
parentab2a237e5cff43f9b8cd806b7e9e271ffb01b461 (diff)
downloadperl6-matrix-client-d8f623d8093ff8e47d386f86e61deebdac66fc29.tar.gz
Add thumbnail endpoint
-rw-r--r--endpoints.md6
-rw-r--r--lib/Matrix/Client/MediaStore.rakumod49
2 files changed, 47 insertions, 8 deletions
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<server-name>, $mxc<media-id>, :$allow-remote)
+ samewith($mxc<server-name>, $mxc<media-id>, :$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<server-name>, $mxc<media-id>,
+ $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<Content-Type>.head,
+ content => $response.content
+ )
+}
+
#| GET - /_matrix/media/r0/config
method config(--> Matrix::Response::MediaStore::Config) {
my $response = $.get("/config");