refactor for ruma cow headers; update for ContentDisposition type

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-12 22:53:07 +00:00
parent f540bed61e
commit 17a54bc4f8
6 changed files with 104 additions and 119 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use conduit::{debug, debug_info, utils::string_from_bytes, Error, Result};
use database::{Database, Map};
use ruma::api::client::error::ErrorKind;
use ruma::{api::client::error::ErrorKind, http_headers::ContentDisposition};
use super::preview::UrlPreviewData;
@ -14,7 +14,7 @@ pub(crate) struct Data {
#[derive(Debug)]
pub(super) struct Metadata {
pub(super) content_disposition: Option<String>,
pub(super) content_disposition: Option<ContentDisposition>,
pub(super) content_type: Option<String>,
pub(super) key: Vec<u8>,
}
@ -29,8 +29,8 @@ impl Data {
}
pub(super) fn create_file_metadata(
&self, sender_user: Option<&str>, mxc: &str, width: u32, height: u32, content_disposition: Option<&str>,
content_type: Option<&str>,
&self, sender_user: Option<&str>, mxc: &str, width: u32, height: u32,
content_disposition: Option<&ContentDisposition>, content_type: Option<&str>,
) -> Result<Vec<u8>> {
let mut key = mxc.as_bytes().to_vec();
key.push(0xFF);
@ -39,9 +39,9 @@ impl Data {
key.push(0xFF);
key.extend_from_slice(
content_disposition
.as_ref()
.map(|f| f.as_bytes())
.unwrap_or_default(),
.map(ToString::to_string)
.unwrap_or_default()
.as_bytes(),
);
key.push(0xFF);
key.extend_from_slice(
@ -143,7 +143,8 @@ impl Data {
} else {
Some(
string_from_bytes(content_disposition_bytes)
.map_err(|_| Error::bad_database("Content Disposition in mediaid_file is invalid unicode."))?,
.map_err(|_| Error::bad_database("Content Disposition in mediaid_file is invalid unicode."))?
.parse()?,
)
};