1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/// Endpoints for the media repository.
pub use *;
use Duration;
use Url;
use ;
use ;
use crateMethod;
use crate;
use crate::;
/// The default duration that the client should be willing to wait to start receiving data.
pub
/// Whether the given duration is the default duration that the client should be willing to wait to
/// start receiving data.
pub
/// `POST /_matrix/media/*/create`
///
/// Create an MXC URI without content.
/// `/v1/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixmediav1create
// const METADATA: Metadata = metadata! {
// method: POST,
// rate_limited: true,
// authentication: AccessToken,
// history: {
// unstable => "/_matrix/media/unstable/fi.mau.msc2246/create",
// 1.7 => "/_matrix/media/v1/create",
// }
// };
/// Response type for the `create_mxc_uri` endpoint.
// impl CreateMxcUriResBody {
// /// Creates a new `Response` with the given MXC URI.
// pub fn new(content_uri: OwnedMxcUri) -> Self {
// Self {
// content_uri,
// unused_expires_at: None,
// }
// }
// }
/// `GET /_matrix/media/*/config`
///
/// Gets the config for the media repository.
/// `/v3/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3config
// const METADATA: Metadata = metadata! {
// method: GET,
// rate_limited: true,
// authentication: AccessToken,
// history: {
// 1.0 => "/_matrix/media/r0/config",
// 1.1 => "/_matrix/media/v3/config",
// }
// };
/// Response type for the `get_media_config` endpoint.
/// `GET /_matrix/media/*/preview_url`
///
/// Get a preview for a URL.
/// `/v3/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3preview_url
// const METADATA: Metadata = metadata! {
// method: GET,
// rate_limited: true,
// authentication: AccessToken,
// history: {
// 1.0 => "/_matrix/media/r0/preview_url",
// 1.1 => "/_matrix/media/v3/preview_url",
// }
// };
// /// Request type for the `get_media_preview` endpoint.
// pub struct MediaPreviewReqBody {
// /// URL to get a preview of.
// #[salvo(parameter(parameter_in = Query))]
// pub url: String,
// /// Preferred point in time (in milliseconds) to return a preview for.
// #[salvo(parameter(parameter_in = Query))]
// pub ts: UnixMillis,
// }
// /// Response type for the `get_media_preview` endpoint.
// #[derive(ToSchema,Serialize, Debug)]
// pub struct MediaPreviewResBody {
// /// OpenGraph-like data for the URL.
// ///
// /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size`
// /// field, and `og:image` returns the MXC URI to the image, if any.
// #[salvo(schema(value_type = Object, additional_properties = true))]
// pub data: Option<Box<RawJsonValue>>,
// }
// impl MediaPreviewResBody {
// /// Creates an empty `Response`.
// pub fn new() -> Self {
// Self { data: None }
// }
// /// Creates a new `Response` with the given OpenGraph data (in a
// /// `serde_json::value::RawValue`).
// pub fn from_raw_value(data: Box<RawJsonValue>) -> Self {
// Self { data: Some(data) }
// }
// /// Creates a new `Response` with the given OpenGraph data (in any kind of serializable
// /// object).
// pub fn from_serialize<T: Serialize>(data: &T) -> serde_json::Result<Self> {
// Ok(Self {
// data: Some(to_raw_json_value(data)?),
// })
// }
// }
/// Request type for the `get_content_thumbnail` endpoint.
// /// Response type for the `get_content_thumbnail` endpoint.
// #[derive(ToSchema, Serialize, Debug)]
// pub struct ThumbnailResBody {
// /// A thumbnail of the requested content.
// #[palpo_api(raw_body)]
// pub file: Vec<u8>,
// /// The content type of the thumbnail.
// #[palpo_api(header = CONTENT_TYPE)]
// pub content_type: Option<String>,
// /// The value of the `Cross-Origin-Resource-Policy` HTTP header.
// ///
// /// See [MDN] for the syntax.
// ///
// /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
// #[palpo_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
// pub cross_origin_resource_policy: Option<String>,
// }
// impl ThumbnailResBody {
// /// Creates a new `Response` with the given thumbnail.
// ///
// /// The Cross-Origin Resource Policy defaults to `cross-origin`.
// pub fn new(file: Vec<u8>) -> Self {
// file,
// content_type: None,
// cross_origin_resource_policy: Some("cross-origin".to_owned()),
// }
// Self {
// }
// }
// #[cfg(test)]
// mod tests {
// use crate::RawJsonValue;
// use assert_matches2::assert_matches;
// use serde_json::{from_value as from_json_value, json, value::to_raw_value as to_raw_json_value};
// // Since BTreeMap<String, Box<RawJsonValue>> deserialization doesn't seem to
// // work, test that Option<RawJsonValue> works
// #[test]
// fn raw_json_deserialize() {
// type OptRawJson = Option<Box<RawJsonValue>>;
// assert_matches!(from_json_value::<OptRawJson>(json!(null)).unwrap(), None);
// from_json_value::<OptRawJson>(json!("test")).unwrap().unwrap();
// from_json_value::<OptRawJson>(json!({ "a": "b" })).unwrap().unwrap();
// }
// // For completeness sake, make sure serialization works too
// #[test]
// fn raw_json_serialize() {
// to_raw_json_value(&json!(null)).unwrap();
// to_raw_json_value(&json!("string")).unwrap();
// to_raw_json_value(&json!({})).unwrap();
// to_raw_json_value(&json!({ "a": "b" })).unwrap();
// }
// }