|
|
@ -5,7 +5,7 @@ use std::mem;
|
|
|
|
|
|
|
|
|
|
|
|
pub struct FileMeta {
|
|
|
|
pub struct FileMeta {
|
|
|
|
pub filename: Option<String>,
|
|
|
|
pub filename: Option<String>,
|
|
|
|
pub content_type: String,
|
|
|
|
pub content_type: Option<String>,
|
|
|
|
pub file: Vec<u8>,
|
|
|
|
pub file: Vec<u8>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -83,12 +83,14 @@ impl Media {
|
|
|
|
let (key, file) = r?;
|
|
|
|
let (key, file) = r?;
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
let content_type = utils::string_from_bytes(
|
|
|
|
let content_type = parts
|
|
|
|
parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|
.map(|bytes| {
|
|
|
|
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?,
|
|
|
|
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
|
|
|
)
|
|
|
|
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
|
|
|
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
|
|
|
})?)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.transpose()?;
|
|
|
|
|
|
|
|
|
|
|
|
let filename_bytes = parts
|
|
|
|
let filename_bytes = parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
@ -158,12 +160,14 @@ impl Media {
|
|
|
|
let (key, file) = r?;
|
|
|
|
let (key, file) = r?;
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
let content_type = utils::string_from_bytes(
|
|
|
|
let content_type = parts
|
|
|
|
parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|
.map(|bytes| {
|
|
|
|
.ok_or_else(|| Error::bad_database("Invalid Media ID in db"))?,
|
|
|
|
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
|
|
|
)
|
|
|
|
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
|
|
|
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
|
|
|
})?)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.transpose()?;
|
|
|
|
|
|
|
|
|
|
|
|
let filename_bytes = parts
|
|
|
|
let filename_bytes = parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
@ -189,12 +193,14 @@ impl Media {
|
|
|
|
let (key, file) = r?;
|
|
|
|
let (key, file) = r?;
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
let mut parts = key.rsplit(|&b| b == 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
let content_type = utils::string_from_bytes(
|
|
|
|
let content_type = parts
|
|
|
|
parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|
.map(|bytes| {
|
|
|
|
.ok_or_else(|| Error::bad_database("Media ID in db is invalid."))?,
|
|
|
|
Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| {
|
|
|
|
)
|
|
|
|
Error::bad_database("Content type in mediaid_file is invalid unicode.")
|
|
|
|
.map_err(|_| Error::bad_database("Content type in mediaid_file is invalid unicode."))?;
|
|
|
|
})?)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.transpose()?;
|
|
|
|
|
|
|
|
|
|
|
|
let filename_bytes = parts
|
|
|
|
let filename_bytes = parts
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|