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
pub mod unstable {
use http::header::CONTENT_TYPE;
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
const METADATA: Metadata = metadata! {
method: PUT,
rate_limited: true,
authentication: AccessToken,
history: {
unstable => "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(path)]
pub server_name: OwnedServerName,
#[ruma_api(path)]
pub media_id: String,
#[ruma_api(raw_body)]
pub file: Vec<u8>,
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<String>,
}
#[response(error = crate::Error)]
pub struct Response {}
impl Request {
pub fn new(media_id: String, server_name: OwnedServerName, file: Vec<u8>) -> Self {
Self { media_id, server_name, file, content_type: None }
}
pub fn from_url(url: &MxcUri, file: Vec<u8>) -> Result<Self, IdParseError> {
let (server_name, media_id) = url.parts()?;
Ok(Self::new(media_id.to_owned(), server_name.to_owned(), file))
}
}
}