Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
4e4f8475
Commit
4e4f8475
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Add method for retrieving thumbnails
parent
71f80c5f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/mtxclient/http/client.hpp
+17
-1
17 additions, 1 deletion
include/mtxclient/http/client.hpp
lib/http/client.cpp
+16
-0
16 additions, 0 deletions
lib/http/client.cpp
tests/media_api.cpp
+25
-18
25 additions, 18 deletions
tests/media_api.cpp
with
58 additions
and
19 deletions
include/mtxclient/http/client.hpp
+
17
−
1
View file @
4e4f8475
...
...
@@ -76,11 +76,23 @@ struct MessagesOpts
uint16_t
limit
=
30
;
};
//! Configuration for thumbnail retrieving.
struct
ThumbOpts
{
//! The desired width of the thumbnail.
uint16_t
width
=
128
;
//! The desired height of the thumbnail.
uint16_t
height
=
128
;
//! The desired resizing method. One of: ["crop", "scale"]
std
::
string
method
=
"crop"
;
//! A mxc URI which points to the content.
std
::
string
mxc_url
;
};
//! The main object that the user will interact.
class
Client
:
public
std
::
enable_shared_from_this
<
Client
>
{
public:
Client
()
=
default
;
Client
(
const
std
::
string
&
server
=
""
,
uint16_t
port
=
443
);
//! Wait for the client to close.
...
...
@@ -191,6 +203,10 @@ public:
const
std
::
string
&
content_type
,
const
std
::
string
&
original_filename
,
RequestErr
err
)
>
cb
);
//! Retrieve a thumbnail from the given mxc url.
void
get_thumbnail
(
const
ThumbOpts
&
opts
,
Callback
<
std
::
string
>
cb
);
//! Send typing notifications to the room.
void
start_typing
(
const
std
::
string
&
room_id
,
uint64_t
timeout
,
ErrCallback
cb
);
//! Remove typing notifications from the room.
...
...
This diff is collapsed.
Click to expand it.
lib/http/client.cpp
+
16
−
0
View file @
4e4f8475
...
...
@@ -234,6 +234,22 @@ Client::download(const std::string &mxc_url,
download
(
url
.
server
,
url
.
media_id
,
std
::
move
(
callback
));
}
void
Client
::
get_thumbnail
(
const
ThumbOpts
&
opts
,
Callback
<
std
::
string
>
callback
)
{
std
::
map
<
std
::
string
,
std
::
string
>
params
;
params
.
emplace
(
"width"
,
std
::
to_string
(
opts
.
width
));
params
.
emplace
(
"height"
,
std
::
to_string
(
opts
.
height
));
params
.
emplace
(
"method"
,
opts
.
method
);
const
auto
mxc
=
mtx
::
client
::
utils
::
parse_mxc_url
(
opts
.
mxc_url
);
const
auto
api_path
=
"/media/r0/thumbnail/"
+
mxc
.
server
+
"/"
+
mxc
.
media_id
+
"?"
+
client
::
utils
::
query_params
(
params
);
get
<
std
::
string
>
(
api_path
,
[
callback
](
const
std
::
string
&
res
,
HeaderFields
,
RequestErr
err
)
{
callback
(
res
,
err
);
});
}
void
Client
::
download
(
const
std
::
string
&
server
,
const
std
::
string
&
media_id
,
...
...
This diff is collapsed.
Click to expand it.
tests/media_api.cpp
+
25
−
18
View file @
4e4f8475
...
...
@@ -104,24 +104,31 @@ TEST(MediaAPI, UploadImage)
const
auto
img
=
read_file
(
"./fixtures/test.jpeg"
);
carl
->
upload
(
img
,
"image/jpeg"
,
"test.jpeg"
,
[
carl
,
img
](
const
mtx
::
responses
::
ContentURI
&
res
,
RequestErr
err
)
{
validate_upload
(
res
,
err
);
carl
->
download
(
res
.
content_uri
,
[
img
](
const
string
&
data
,
const
string
&
content_type
,
const
string
&
original_filename
,
RequestErr
err
)
{
ASSERT_FALSE
(
err
);
EXPECT_EQ
(
data
,
img
);
EXPECT_EQ
(
content_type
,
"image/jpeg"
);
EXPECT_EQ
(
original_filename
,
"test.jpeg"
);
});
});
carl
->
upload
(
img
,
"image/jpeg"
,
"test.jpeg"
,
[
carl
,
img
](
const
mtx
::
responses
::
ContentURI
&
res
,
RequestErr
err
)
{
validate_upload
(
res
,
err
);
ThumbOpts
opts
;
opts
.
mxc_url
=
res
.
content_uri
;
carl
->
get_thumbnail
(
opts
,
[](
const
std
::
string
&
res
,
RequestErr
err
)
{
ASSERT_FALSE
(
err
);
ASSERT_FALSE
(
res
.
empty
());
});
carl
->
download
(
res
.
content_uri
,
[
img
](
const
string
&
data
,
const
string
&
content_type
,
const
string
&
original_filename
,
RequestErr
err
)
{
ASSERT_FALSE
(
err
);
EXPECT_EQ
(
data
,
img
);
EXPECT_EQ
(
content_type
,
"image/jpeg"
);
EXPECT_EQ
(
original_filename
,
"test.jpeg"
);
});
});
});
carl
->
close
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment