ruma_client_api/media/
get_content_as_filename.rs1pub mod v3 {
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::NoAuthentication, request, response},
16 http_headers::ContentDisposition,
17 metadata,
18 };
19
20 use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY;
21
22 metadata! {
23 method: GET,
24 rate_limited: false,
25 authentication: NoAuthentication,
26 history: {
27 1.0 => "/_matrix/media/r0/download/{server_name}/{media_id}/{filename}",
28 1.1 => "/_matrix/media/v3/download/{server_name}/{media_id}/{filename}",
29 1.11 => deprecated,
30 }
31 }
32
33 #[request(error = crate::Error)]
35 #[deprecated = "\
36 Since Matrix 1.11, clients should use `authenticated_media::get_content_as_filename::v1::Request` \
37 instead if the homeserver supports it.\
38 "]
39 pub struct Request {
40 #[ruma_api(path)]
42 pub server_name: OwnedServerName,
43
44 #[ruma_api(path)]
46 pub media_id: String,
47
48 #[ruma_api(path)]
50 pub filename: String,
51
52 #[ruma_api(query)]
56 #[serde(
57 default = "ruma_common::serde::default_true",
58 skip_serializing_if = "ruma_common::serde::is_true"
59 )]
60 pub allow_remote: bool,
61
62 #[ruma_api(query)]
67 #[serde(
68 with = "ruma_common::serde::duration::ms",
69 default = "ruma_common::media::default_download_timeout",
70 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
71 )]
72 pub timeout_ms: Duration,
73
74 #[ruma_api(query)]
79 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
80 pub allow_redirect: bool,
81 }
82
83 #[response(error = crate::Error)]
85 pub struct Response {
86 #[ruma_api(raw_body)]
88 pub file: Vec<u8>,
89
90 #[ruma_api(header = CONTENT_TYPE)]
92 pub content_type: Option<String>,
93
94 #[ruma_api(header = CONTENT_DISPOSITION)]
97 pub content_disposition: Option<ContentDisposition>,
98
99 #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
105 pub cross_origin_resource_policy: Option<String>,
106 }
107
108 #[allow(deprecated)]
109 impl Request {
110 pub fn new(media_id: String, server_name: OwnedServerName, filename: String) -> Self {
112 Self {
113 media_id,
114 server_name,
115 filename,
116 allow_remote: true,
117 timeout_ms: ruma_common::media::default_download_timeout(),
118 allow_redirect: false,
119 }
120 }
121
122 pub fn from_url(url: &MxcUri, filename: String) -> Result<Self, IdParseError> {
124 let (server_name, media_id) = url.parts()?;
125
126 Ok(Self::new(media_id.to_owned(), server_name.to_owned(), filename))
127 }
128 }
129
130 impl Response {
131 pub fn new(
135 file: Vec<u8>,
136 content_type: String,
137 content_disposition: ContentDisposition,
138 ) -> Self {
139 Self {
140 file,
141 content_type: Some(content_type),
142 content_disposition: Some(content_disposition),
143 cross_origin_resource_policy: Some("cross-origin".to_owned()),
144 }
145 }
146 }
147}