ruma_federation_api/authenticated_media/get_content_thumbnail/
unstable.rs1use std::time::Duration;
6
7use js_int::UInt;
8use ruma_common::{
9 api::{Metadata, path_builder::SinglePath, request},
10 media::Method,
11};
12
13use crate::authenticated_media::{ContentMetadata, FileOrLocation, ResponseBody};
14
15#[request]
17pub struct Request {
18 #[ruma_api(path)]
20 pub media_id: String,
21
22 #[ruma_api(query)]
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub method: Option<Method>,
26
27 #[ruma_api(query)]
31 pub width: UInt,
32
33 #[ruma_api(query)]
37 pub height: UInt,
38
39 #[ruma_api(query)]
44 #[serde(
45 with = "ruma_common::serde::duration::ms",
46 default = "ruma_common::media::default_download_timeout",
47 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
48 )]
49 pub timeout_ms: Duration,
50
51 #[ruma_api(query)]
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub animated: Option<bool>,
59}
60
61impl Request {
62 pub fn new(media_id: String, width: UInt, height: UInt) -> Self {
65 Self {
66 media_id,
67 method: None,
68 width,
69 height,
70 timeout_ms: ruma_common::media::default_download_timeout(),
71 animated: None,
72 }
73 }
74}
75
76impl Metadata for Request {
77 const METHOD: http::Method = super::v1::Request::METHOD;
78 const RATE_LIMITED: bool = super::v1::Request::RATE_LIMITED;
79 type Authentication = <super::v1::Request as Metadata>::Authentication;
80 type PathBuilder = <super::v1::Request as Metadata>::PathBuilder;
81 const PATH_BUILDER: Self::PathBuilder = SinglePath::new(
82 "/_matrix/federation/unstable/org.matrix.msc3916.v2/media/thumbnail/{media_id}",
83 );
84}
85
86impl From<super::v1::Request> for Request {
87 fn from(value: super::v1::Request) -> Self {
88 let super::v1::Request { media_id, method, width, height, timeout_ms, animated } = value;
89 Self { media_id, method, width, height, timeout_ms, animated }
90 }
91}
92
93impl From<Request> for super::v1::Request {
94 fn from(value: Request) -> Self {
95 let Request { media_id, method, width, height, timeout_ms, animated } = value;
96 Self { media_id, method, width, height, timeout_ms, animated }
97 }
98}
99
100#[derive(Debug, Clone)]
102#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
103pub struct Response {
104 pub metadata: ContentMetadata,
106
107 pub content: FileOrLocation,
109}
110
111impl Response {
112 pub fn new(metadata: ContentMetadata, content: FileOrLocation) -> Self {
114 Self { metadata, content }
115 }
116}
117
118#[cfg(feature = "client")]
119impl ruma_common::api::IncomingResponse for Response {
120 type EndpointError = <super::v1::Response as ruma_common::api::IncomingResponse>::EndpointError;
121
122 fn try_from_http_response_inner(
123 http_response: http::Response<&[u8]>,
124 ) -> Result<Self, ruma_common::api::error::DeserializationError> {
125 let ResponseBody { metadata, content, .. } =
126 ResponseBody::try_from_http_response(http_response)?;
127 Ok(Self { metadata, content })
128 }
129}
130
131#[cfg(feature = "server")]
132impl ruma_common::api::OutgoingResponse for Response {
133 type Body = ResponseBody;
134
135 fn try_into_http_response_inner(
136 self,
137 ) -> Result<http::Response<Self::Body>, ruma_common::api::error::IntoHttpError> {
138 ResponseBody::new(self.metadata, self.content).try_into_http_response()
139 }
140}
141
142impl From<super::v1::Response> for Response {
143 fn from(value: super::v1::Response) -> Self {
144 let super::v1::Response { metadata, content } = value;
145 Self { metadata, content }
146 }
147}
148
149impl From<Response> for super::v1::Response {
150 fn from(value: Response) -> Self {
151 let Response { metadata, content } = value;
152 Self { metadata, content }
153 }
154}