put media in filesystem

This commit is contained in:
hamidreza kalbasi 2021-06-04 08:06:12 +04:30 committed by Timo Kösters
parent d0ee823254
commit 972caacdc2
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
6 changed files with 78 additions and 30 deletions

View file

@ -38,6 +38,7 @@ pub async fn create_content_route(
);
db.media.create(
mxc.clone(),
&db.globals,
&body
.filename
.as_ref()
@ -45,7 +46,7 @@ pub async fn create_content_route(
.as_deref(),
&body.content_type.as_deref(),
&body.file,
)?;
).await?;
db.flush().await?;
@ -71,7 +72,7 @@ pub async fn get_content_route(
content_disposition,
content_type,
file,
}) = db.media.get(&mxc)?
}) = db.media.get(&db.globals, &mxc).await?
{
Ok(get_content::Response {
file,
@ -95,10 +96,11 @@ pub async fn get_content_route(
db.media.create(
mxc,
&db.globals,
&get_content_response.content_disposition.as_deref(),
&get_content_response.content_type.as_deref(),
&get_content_response.file,
)?;
).await?;
Ok(get_content_response.into())
} else {
@ -121,13 +123,14 @@ pub async fn get_content_thumbnail_route(
content_type, file, ..
}) = db.media.get_thumbnail(
mxc.clone(),
&db.globals,
body.width
.try_into()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?,
body.height
.try_into()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?,
)? {
).await? {
Ok(get_content_thumbnail::Response { file, content_type }.into())
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
let get_thumbnail_response = db
@ -148,12 +151,13 @@ pub async fn get_content_thumbnail_route(
db.media.upload_thumbnail(
mxc,
&db.globals,
&None,
&get_thumbnail_response.content_type,
body.width.try_into().expect("all UInts are valid u32s"),
body.height.try_into().expect("all UInts are valid u32s"),
&get_thumbnail_response.file,
)?;
).await?;
Ok(get_thumbnail_response.into())
} else {