feat: media

This commit is contained in:
timokoesters 2020-05-18 17:53:34 +02:00
parent 42ae433b25
commit 821c608c6a
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
5 changed files with 132 additions and 13 deletions

View file

@ -11,7 +11,7 @@ use ruma_identifiers::UserId;
use std::{convert::TryInto, io::Cursor, ops::Deref};
use tokio::io::AsyncReadExt;
const MESSAGE_LIMIT: u64 = 65535;
const MESSAGE_LIMIT: u64 = 20 * 1024 * 1024; // 20 MB
/// This struct converts rocket requests into ruma structs by converting them into http requests
/// first.
@ -19,7 +19,7 @@ pub struct Ruma<T> {
body: T,
pub user_id: Option<UserId>,
pub device_id: Option<String>,
pub json_body: serde_json::Value,
pub json_body: Option<serde_json::Value>, // This is None if parsing failed (for raw byte bodies)
}
impl<'a, T: Endpoint> FromData<'a> for Ruma<T> {
@ -85,12 +85,8 @@ impl<'a, T: Endpoint> FromData<'a> for Ruma<T> {
body: t,
user_id,
device_id,
// TODO: Can we avoid parsing it again?
json_body: if !body.is_empty() {
serde_json::from_slice(&body).expect("Ruma already parsed it successfully")
} else {
serde_json::Value::default()
},
// TODO: Can we avoid parsing it again? (We only need this for append_pdu)
json_body: serde_json::from_slice(&body).ok()
}),
Err(e) => {
warn!("{:?}", e);