Have Media db return optional content_type, conversion fixes

This commit is contained in:
Devin Ragotzy 2020-11-18 08:36:12 -05:00 committed by Timo Kösters
parent bb24f6ad90
commit b6d721374f
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
5 changed files with 47 additions and 31 deletions

View file

@ -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()