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::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}",
28 1.1 => "/_matrix/media/v3/download/{server_name}/{media_id}",
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::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(query)]
52 #[serde(
53 default = "ruma_common::serde::default_true",
54 skip_serializing_if = "ruma_common::serde::is_true"
55 )]
56 pub allow_remote: bool,
57
58 #[ruma_api(query)]
63 #[serde(
64 with = "ruma_common::serde::duration::ms",
65 default = "ruma_common::media::default_download_timeout",
66 skip_serializing_if = "ruma_common::media::is_default_download_timeout"
67 )]
68 pub timeout_ms: Duration,
69
70 #[ruma_api(query)]
75 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
76 pub allow_redirect: bool,
77 }
78
79 #[response(error = crate::Error)]
81 pub struct Response {
82 #[ruma_api(raw_body)]
84 pub file: Vec<u8>,
85
86 #[ruma_api(header = CONTENT_TYPE)]
88 pub content_type: Option<String>,
89
90 #[ruma_api(header = CONTENT_DISPOSITION)]
93 pub content_disposition: Option<ContentDisposition>,
94
95 #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
101 pub cross_origin_resource_policy: Option<String>,
102 }
103
104 #[allow(deprecated)]
105 impl Request {
106 pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
108 Self {
109 media_id,
110 server_name,
111 allow_remote: true,
112 timeout_ms: ruma_common::media::default_download_timeout(),
113 allow_redirect: false,
114 }
115 }
116
117 pub fn from_url(url: &MxcUri) -> Result<Self, IdParseError> {
119 let (server_name, media_id) = url.parts()?;
120
121 Ok(Self::new(media_id.to_owned(), server_name.to_owned()))
122 }
123 }
124
125 impl Response {
126 pub fn new(
130 file: Vec<u8>,
131 content_type: String,
132 content_disposition: ContentDisposition,
133 ) -> Self {
134 Self {
135 file,
136 content_type: Some(content_type),
137 content_disposition: Some(content_disposition),
138 cross_origin_resource_policy: Some("cross-origin".to_owned()),
139 }
140 }
141 }
142}