improvements on blurhashing feature
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
62180897c0
commit
442bb9889c
7 changed files with 87 additions and 81 deletions
|
@ -17,7 +17,6 @@ crate-type = [
|
|||
]
|
||||
|
||||
[features]
|
||||
blurhashing=[]
|
||||
element_hacks = []
|
||||
release_max_log_level = [
|
||||
"tracing/max_level_trace",
|
||||
|
|
|
@ -57,40 +57,28 @@ pub(crate) async fn create_content_route(
|
|||
let filename = body.filename.as_deref();
|
||||
let content_type = body.content_type.as_deref();
|
||||
let content_disposition = make_content_disposition(None, content_type, filename);
|
||||
let mxc = Mxc {
|
||||
let ref mxc = Mxc {
|
||||
server_name: services.globals.server_name(),
|
||||
media_id: &utils::random_string(MXC_LENGTH),
|
||||
};
|
||||
|
||||
#[cfg(feature = "blurhashing")]
|
||||
{
|
||||
if body.generate_blurhash {
|
||||
let (blurhash, create_media_result) = tokio::join!(
|
||||
services
|
||||
.media
|
||||
.create_blurhash(&body.file, content_type, filename),
|
||||
services.media.create(
|
||||
&mxc,
|
||||
Some(user),
|
||||
Some(&content_disposition),
|
||||
content_type,
|
||||
&body.file
|
||||
)
|
||||
);
|
||||
return create_media_result.map(|()| create_content::v3::Response {
|
||||
content_uri: mxc.to_string().into(),
|
||||
blurhash,
|
||||
});
|
||||
}
|
||||
}
|
||||
services
|
||||
.media
|
||||
.create(&mxc, Some(user), Some(&content_disposition), content_type, &body.file)
|
||||
.await
|
||||
.map(|()| create_content::v3::Response {
|
||||
content_uri: mxc.to_string().into(),
|
||||
blurhash: None,
|
||||
})
|
||||
.create(mxc, Some(user), Some(&content_disposition), content_type, &body.file)
|
||||
.await?;
|
||||
|
||||
let blurhash = body.generate_blurhash.then(|| {
|
||||
services
|
||||
.media
|
||||
.create_blurhash(&body.file, content_type, filename)
|
||||
.ok()
|
||||
.flatten()
|
||||
});
|
||||
|
||||
Ok(create_content::v3::Response {
|
||||
content_uri: mxc.to_string().into(),
|
||||
blurhash: blurhash.flatten(),
|
||||
})
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue