ruma_client_api/authenticated_media/
get_content.rs1pub mod v1 {
6 use std::time::Duration;
11
12 use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
13 use ruma_common::{
14 api::{request, response, Metadata},
15 http_headers::ContentDisposition,
16 metadata, IdParseError, MxcUri, OwnedServerName,
17 };
18
19 const METADATA: Metadata = metadata! {
20 method: GET,
21 rate_limited: true,
22 authentication: AccessToken,
23 history: {
24 unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/download/:server_name/:media_id",
25 1.11 => "/_matrix/client/v1/media/download/:server_name/:media_id",
26 }
27 };
28
29 #[request(error = crate::Error)]
31 pub struct Request {
32 #[ruma_api(path)]
34 pub server_name: OwnedServerName,
35
36 #[ruma_api(path)]
38 pub media_id: String,
39
40 #[ruma_api(query)]
45 #[serde(
46 with = "ruma_common::serde::duration::ms",
47 default = "ruma_common::media::default_download_timeout",
48 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
49 )]
50 pub timeout_ms: Duration,
51 }
52
53 #[response(error = crate::Error)]
55 pub struct Response {
56 #[ruma_api(raw_body)]
58 pub file: Vec<u8>,
59
60 #[ruma_api(header = CONTENT_TYPE)]
62 pub content_type: Option<String>,
63
64 #[ruma_api(header = CONTENT_DISPOSITION)]
67 pub content_disposition: Option<ContentDisposition>,
68 }
69
70 impl Request {
71 pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
73 Self {
74 media_id,
75 server_name,
76 timeout_ms: ruma_common::media::default_download_timeout(),
77 }
78 }
79
80 pub fn from_uri(uri: &MxcUri) -> Result<Self, IdParseError> {
82 let (server_name, media_id) = uri.parts()?;
83
84 Ok(Self::new(media_id.to_owned(), server_name.to_owned()))
85 }
86 }
87
88 impl Response {
89 pub fn new(
91 file: Vec<u8>,
92 content_type: String,
93 content_disposition: ContentDisposition,
94 ) -> Self {
95 Self {
96 file,
97 content_type: Some(content_type),
98 content_disposition: Some(content_disposition),
99 }
100 }
101 }
102}