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