refactor for ruma cow headers; update for ContentDisposition type
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f540bed61e
commit
17a54bc4f8
6 changed files with 104 additions and 119 deletions
|
@ -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()?,
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use async_trait::async_trait;
|
|||
use base64::{engine::general_purpose, Engine as _};
|
||||
use conduit::{debug, debug_error, err, error, trace, utils, utils::MutexMap, Err, Result, Server};
|
||||
use data::{Data, Metadata};
|
||||
use ruma::{OwnedMxcUri, OwnedUserId};
|
||||
use ruma::{http_headers::ContentDisposition, OwnedMxcUri, OwnedUserId};
|
||||
use tokio::{
|
||||
fs,
|
||||
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
||||
|
@ -21,7 +21,7 @@ use crate::{client, globals, Dep};
|
|||
pub struct FileMeta {
|
||||
pub content: Option<Vec<u8>>,
|
||||
pub content_type: Option<String>,
|
||||
pub content_disposition: Option<String>,
|
||||
pub content_disposition: Option<ContentDisposition>,
|
||||
}
|
||||
|
||||
pub struct Service {
|
||||
|
@ -65,7 +65,7 @@ impl crate::Service for Service {
|
|||
impl Service {
|
||||
/// Uploads a file.
|
||||
pub async fn create(
|
||||
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&str>,
|
||||
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&ContentDisposition>,
|
||||
content_type: Option<&str>, file: &[u8],
|
||||
) -> Result<()> {
|
||||
// Width, Height = 0 if it's not a thumbnail
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{cmp, io::Cursor, num::Saturating as Sat};
|
|||
|
||||
use conduit::{checked, Result};
|
||||
use image::{imageops::FilterType, DynamicImage};
|
||||
use ruma::OwnedUserId;
|
||||
use ruma::{http_headers::ContentDisposition, OwnedUserId};
|
||||
use tokio::{
|
||||
fs,
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
|
@ -14,7 +14,7 @@ impl super::Service {
|
|||
/// Uploads or replaces a file thumbnail.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn upload_thumbnail(
|
||||
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&str>,
|
||||
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&ContentDisposition>,
|
||||
content_type: Option<&str>, width: u32, height: u32, file: &[u8],
|
||||
) -> Result<()> {
|
||||
let key = if let Some(user) = sender_user {
|
||||
|
@ -104,7 +104,7 @@ impl super::Service {
|
|||
mxc,
|
||||
width,
|
||||
height,
|
||||
data.content_disposition.as_deref(),
|
||||
data.content_disposition.as_ref(),
|
||||
data.content_type.as_deref(),
|
||||
)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue