Have Media db return optional content_type, conversion fixes
This commit is contained in:
parent
bb24f6ad90
commit
b6d721374f
5 changed files with 47 additions and 31 deletions
|
@ -5,7 +5,7 @@ use std::mem;
|
|||
|
||||
pub struct FileMeta {
|
||||
pub filename: Option<String>,
|
||||
pub content_type: String,
|
||||
pub content_type: Option<String>,
|
||||
pub file: Vec<u8>,
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,14 @@ impl Media {
|
|||
let (key, file) = r?;
|
||||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let content_type = utils::string_from_bytes(
|
||||
parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
||||
let content_type = parts
|
||||
.next()
|
||||
.map(|bytes| {
|
||||
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
||||
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
||||
})?)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let filename_bytes = parts
|
||||
.next()
|
||||
|
@ -158,12 +160,14 @@ impl Media {
|
|||
let (key, file) = r?;
|
||||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let content_type = utils::string_from_bytes(
|
||||
parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Invalid Media ID in db"))?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
||||
let content_type = parts
|
||||
.next()
|
||||
.map(|bytes| {
|
||||
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
||||
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
||||
})?)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let filename_bytes = parts
|
||||
.next()
|
||||
|
@ -189,12 +193,14 @@ impl Media {
|
|||
let (key, file) = r?;
|
||||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let content_type = utils::string_from_bytes(
|
||||
parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
||||
let content_type = parts
|
||||
.next()
|
||||
.map(|bytes| {
|
||||
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
||||
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
||||
})?)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let filename_bytes = parts
|
||||
.next()
|
||||
|
|
|
@ -499,7 +499,6 @@ impl Rooms {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
/// Creates a new persisted data unit and adds it to a room.
|
||||
///
|
||||
/// By this point the incoming event should be fully authenticated, no auth happens
|
||||
|
@ -856,9 +855,8 @@ impl Rooms {
|
|||
};
|
||||
|
||||
// Hash and sign
|
||||
let mut pdu_json: BTreeMap<String, ruma::serde::CanonicalJsonValue> =
|
||||
serde_json::from_value(serde_json::json!(&pdu))
|
||||
.expect("event is valid, we just created it");
|
||||
let mut pdu_json =
|
||||
utils::to_canonical_object(&pdu).expect("event is valid, we just created it");
|
||||
|
||||
pdu_json.remove("event_id");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue