put media in filesystem
This commit is contained in:
parent
d0ee823254
commit
972caacdc2
6 changed files with 78 additions and 30 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue