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 IdParseError, MxcUri, OwnedServerName,
15 api::{auth_scheme::AccessToken, request, response},
16 http_headers::ContentDisposition,
17 metadata,
18 };
19
20 metadata! {
21 method: GET,
22 rate_limited: true,
23 authentication: AccessToken,
24 history: {
25 unstable("org.matrix.msc3916") => "/_matrix/client/unstable/org.matrix.msc3916/media/download/{server_name}/{media_id}",
26 1.11 | stable("org.matrix.msc3916.stable") => "/_matrix/client/v1/media/download/{server_name}/{media_id}",
27 }
28 }
29
30 #[request(error = crate::Error)]
32 pub struct Request {
33 #[ruma_api(path)]
35 pub server_name: OwnedServerName,
36
37 #[ruma_api(path)]
39 pub media_id: String,
40
41 #[ruma_api(query)]
46 #[serde(
47 with = "ruma_common::serde::duration::ms",
48 default = "ruma_common::media::default_download_timeout",
49 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
50 )]
51 pub timeout_ms: Duration,
52 }
53
54 #[response(error = crate::Error)]
56 pub struct Response {
57 #[ruma_api(raw_body)]
59 pub file: Vec<u8>,
60
61 #[ruma_api(header = CONTENT_TYPE)]
63 pub content_type: Option<String>,
64
65 #[ruma_api(header = CONTENT_DISPOSITION)]
68 pub content_disposition: Option<ContentDisposition>,
69 }
70
71 impl Request {
72 pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
74 Self {
75 media_id,
76 server_name,
77 timeout_ms: ruma_common::media::default_download_timeout(),
78 }
79 }
80
81 pub fn from_uri(uri: &MxcUri) -> Result<Self, IdParseError> {
83 let (server_name, media_id) = uri.parts()?;
84
85 Ok(Self::new(media_id.to_owned(), server_name.to_owned()))
86 }
87 }
88
89 impl Response {
90 pub fn new(
92 file: Vec<u8>,
93 content_type: String,
94 content_disposition: ContentDisposition,
95 ) -> Self {
96 Self {
97 file,
98 content_type: Some(content_type),
99 content_disposition: Some(content_disposition),
100 }
101 }
102 }
103}