ruma_client_api/authenticated_media/
get_content_as_filename.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}/{filename}",
26 1.11 | stable("org.matrix.msc3916.stable") => "/_matrix/client/v1/media/download/{server_name}/{media_id}/{filename}",
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(path)]
43 pub filename: String,
44
45 #[ruma_api(query)]
50 #[serde(
51 with = "ruma_common::serde::duration::ms",
52 default = "ruma_common::media::default_download_timeout",
53 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
54 )]
55 pub timeout_ms: Duration,
56 }
57
58 #[response(error = crate::Error)]
60 pub struct Response {
61 #[ruma_api(raw_body)]
63 pub file: Vec<u8>,
64
65 #[ruma_api(header = CONTENT_TYPE)]
67 pub content_type: Option<String>,
68
69 #[ruma_api(header = CONTENT_DISPOSITION)]
72 pub content_disposition: Option<ContentDisposition>,
73 }
74
75 impl Request {
76 pub fn new(media_id: String, server_name: OwnedServerName, filename: String) -> Self {
78 Self {
79 media_id,
80 server_name,
81 filename,
82 timeout_ms: ruma_common::media::default_download_timeout(),
83 }
84 }
85
86 pub fn from_uri(uri: &MxcUri, filename: String) -> Result<Self, IdParseError> {
88 let (server_name, media_id) = uri.parts()?;
89
90 Ok(Self::new(media_id.to_owned(), server_name.to_owned(), filename))
91 }
92 }
93
94 impl Response {
95 pub fn new(
97 file: Vec<u8>,
98 content_type: String,
99 content_disposition: ContentDisposition,
100 ) -> Self {
101 Self {
102 file,
103 content_type: Some(content_type),
104 content_disposition: Some(content_disposition),
105 }
106 }
107 }
108}