|
|
|
@ -36,7 +36,9 @@ pub async fn create_content_route( |
|
|
|
db.globals.server_name(), |
|
|
|
db.globals.server_name(), |
|
|
|
utils::random_string(MXC_LENGTH) |
|
|
|
utils::random_string(MXC_LENGTH) |
|
|
|
); |
|
|
|
); |
|
|
|
db.media.create( |
|
|
|
|
|
|
|
|
|
|
|
db.media |
|
|
|
|
|
|
|
.create( |
|
|
|
mxc.clone(), |
|
|
|
mxc.clone(), |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
&body |
|
|
|
&body |
|
|
|
@ -46,7 +48,8 @@ pub async fn create_content_route( |
|
|
|
.as_deref(), |
|
|
|
.as_deref(), |
|
|
|
&body.content_type.as_deref(), |
|
|
|
&body.content_type.as_deref(), |
|
|
|
&body.file, |
|
|
|
&body.file, |
|
|
|
).await?; |
|
|
|
) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
db.flush().await?; |
|
|
|
db.flush().await?; |
|
|
|
|
|
|
|
|
|
|
|
@ -94,13 +97,15 @@ pub async fn get_content_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.await?; |
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
db.media.create( |
|
|
|
db.media |
|
|
|
|
|
|
|
.create( |
|
|
|
mxc, |
|
|
|
mxc, |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
&get_content_response.content_disposition.as_deref(), |
|
|
|
&get_content_response.content_disposition.as_deref(), |
|
|
|
&get_content_response.content_type.as_deref(), |
|
|
|
&get_content_response.content_type.as_deref(), |
|
|
|
&get_content_response.file, |
|
|
|
&get_content_response.file, |
|
|
|
).await?; |
|
|
|
) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
Ok(get_content_response.into()) |
|
|
|
Ok(get_content_response.into()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -121,7 +126,9 @@ pub async fn get_content_thumbnail_route( |
|
|
|
|
|
|
|
|
|
|
|
if let Some(FileMeta { |
|
|
|
if let Some(FileMeta { |
|
|
|
content_type, file, .. |
|
|
|
content_type, file, .. |
|
|
|
}) = db.media.get_thumbnail( |
|
|
|
}) = db |
|
|
|
|
|
|
|
.media |
|
|
|
|
|
|
|
.get_thumbnail( |
|
|
|
mxc.clone(), |
|
|
|
mxc.clone(), |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
body.width |
|
|
|
body.width |
|
|
|
@ -130,7 +137,9 @@ pub async fn get_content_thumbnail_route( |
|
|
|
body.height |
|
|
|
body.height |
|
|
|
.try_into() |
|
|
|
.try_into() |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
).await? { |
|
|
|
) |
|
|
|
|
|
|
|
.await? |
|
|
|
|
|
|
|
{ |
|
|
|
Ok(get_content_thumbnail::Response { file, content_type }.into()) |
|
|
|
Ok(get_content_thumbnail::Response { file, content_type }.into()) |
|
|
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote { |
|
|
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote { |
|
|
|
let get_thumbnail_response = db |
|
|
|
let get_thumbnail_response = db |
|
|
|
@ -149,7 +158,8 @@ pub async fn get_content_thumbnail_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.await?; |
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
db.media.upload_thumbnail( |
|
|
|
db.media |
|
|
|
|
|
|
|
.upload_thumbnail( |
|
|
|
mxc, |
|
|
|
mxc, |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
&None, |
|
|
|
&None, |
|
|
|
@ -157,7 +167,8 @@ pub async fn get_content_thumbnail_route( |
|
|
|
body.width.try_into().expect("all UInts are valid u32s"), |
|
|
|
body.width.try_into().expect("all UInts are valid u32s"), |
|
|
|
body.height.try_into().expect("all UInts are valid u32s"), |
|
|
|
body.height.try_into().expect("all UInts are valid u32s"), |
|
|
|
&get_thumbnail_response.file, |
|
|
|
&get_thumbnail_response.file, |
|
|
|
).await?; |
|
|
|
) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
Ok(get_thumbnail_response.into()) |
|
|
|
Ok(get_thumbnail_response.into()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|