ruma_client_api/media/
get_content.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::NoAccessToken, request, response},
16 http_headers::{CROSS_ORIGIN_RESOURCE_POLICY, ContentDisposition},
17 metadata,
18 };
19
20 metadata! {
21 method: GET,
22 rate_limited: false,
23 authentication: NoAccessToken,
24 history: {
25 1.0 => "/_matrix/media/r0/download/{server_name}/{media_id}",
26 1.1 => "/_matrix/media/v3/download/{server_name}/{media_id}",
27 1.11 => deprecated,
28 }
29 }
30
31 #[request]
33 #[deprecated = "\
34 Since Matrix 1.11, clients should use `authenticated_media::get_content::v1::Request` \
35 instead if the homeserver supports it.\
36 "]
37 pub struct Request {
38 #[ruma_api(path)]
40 pub server_name: OwnedServerName,
41
42 #[ruma_api(path)]
44 pub media_id: String,
45
46 #[ruma_api(query)]
50 #[serde(
51 default = "ruma_common::serde::default_true",
52 skip_serializing_if = "ruma_common::serde::is_true"
53 )]
54 pub allow_remote: bool,
55
56 #[ruma_api(query)]
61 #[serde(
62 with = "ruma_common::serde::duration::ms",
63 default = "ruma_common::media::default_download_timeout",
64 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
65 )]
66 pub timeout_ms: Duration,
67
68 #[ruma_api(query)]
73 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
74 pub allow_redirect: bool,
75 }
76
77 #[response]
79 pub struct Response {
80 #[ruma_api(raw_body)]
82 pub file: Vec<u8>,
83
84 #[ruma_api(header = CONTENT_TYPE)]
86 pub content_type: Option<String>,
87
88 #[ruma_api(header = CONTENT_DISPOSITION)]
91 pub content_disposition: Option<ContentDisposition>,
92
93 #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
99 pub cross_origin_resource_policy: Option<String>,
100 }
101
102 #[allow(deprecated)]
103 impl Request {
104 pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
106 Self {
107 media_id,
108 server_name,
109 allow_remote: true,
110 timeout_ms: ruma_common::media::default_download_timeout(),
111 allow_redirect: false,
112 }
113 }
114
115 pub fn from_url(url: &MxcUri) -> Result<Self, IdParseError> {
117 let (server_name, media_id) = url.parts()?;
118
119 Ok(Self::new(media_id.to_owned(), server_name.to_owned()))
120 }
121 }
122
123 impl Response {
124 pub fn new(
128 file: Vec<u8>,
129 content_type: String,
130 content_disposition: ContentDisposition,
131 ) -> Self {
132 Self {
133 file,
134 content_type: Some(content_type),
135 content_disposition: Some(content_disposition),
136 cross_origin_resource_policy: Some("cross-origin".to_owned()),
137 }
138 }
139 }
140}