fix: some compile time errors

Only 174 errors left!
This commit is contained in:
Timo Kösters 2022-09-06 23:15:09 +02:00 committed by Nyaaori
parent 82e7f57b38
commit 057f8364cc
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
118 changed files with 2139 additions and 2433 deletions

View file

@ -1,6 +1,5 @@
use crate::{
database::{media::FileMeta, DatabaseGuard},
utils, Error, Result, Ruma,
utils, Error, Result, Ruma, services, service::media::FileMeta,
};
use ruma::api::client::{
error::ErrorKind,
@ -16,11 +15,10 @@ const MXC_LENGTH: usize = 32;
///
/// Returns max upload size.
pub async fn get_media_config_route(
db: DatabaseGuard,
_body: Ruma<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> {
Ok(get_media_config::v3::Response {
upload_size: db.globals.max_request_size().into(),
upload_size: services().globals.max_request_size().into(),
})
}
@ -31,19 +29,17 @@ pub async fn get_media_config_route(
/// - Some metadata will be saved in the database
/// - Media will be saved in the media/ directory
pub async fn create_content_route(
db: DatabaseGuard,
body: Ruma<create_content::v3::IncomingRequest>,
) -> Result<create_content::v3::Response> {
let mxc = format!(
"mxc://{}/{}",
db.globals.server_name(),
services().globals.server_name(),
utils::random_string(MXC_LENGTH)
);
db.media
services().media
.create(
mxc.clone(),
&db.globals,
&body
.filename
.as_ref()
@ -54,8 +50,6 @@ pub async fn create_content_route(
)
.await?;
db.flush()?;
Ok(create_content::v3::Response {
content_uri: mxc.try_into().expect("Invalid mxc:// URI"),
blurhash: None,
@ -63,15 +57,13 @@ pub async fn create_content_route(
}
pub async fn get_remote_content(
db: &DatabaseGuard,
mxc: &str,
server_name: &ruma::ServerName,
media_id: &str,
) -> Result<get_content::v3::Response, Error> {
let content_response = db
let content_response = services()
.sending
.send_federation_request(
&db.globals,
server_name,
get_content::v3::Request {
allow_remote: false,
@ -81,10 +73,9 @@ pub async fn get_remote_content(
)
.await?;
db.media
services().media
.create(
mxc.to_string(),
&db.globals,
&content_response.content_disposition.as_deref(),
&content_response.content_type.as_deref(),
&content_response.file,
@ -100,7 +91,6 @@ pub async fn get_remote_content(
///
/// - Only allows federation if `allow_remote` is true
pub async fn get_content_route(
db: DatabaseGuard,
body: Ruma<get_content::v3::IncomingRequest>,
) -> Result<get_content::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
@ -109,16 +99,16 @@ pub async fn get_content_route(
content_disposition,
content_type,
file,
}) = db.media.get(&db.globals, &mxc).await?
}) = services().media.get(&mxc).await?
{
Ok(get_content::v3::Response {
file,
content_type,
content_disposition,
})
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
let remote_content_response =
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
get_remote_content(&mxc, &body.server_name, &body.media_id).await?;
Ok(remote_content_response)
} else {
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
@ -131,7 +121,6 @@ pub async fn get_content_route(
///
/// - Only allows federation if `allow_remote` is true
pub async fn get_content_as_filename_route(
db: DatabaseGuard,
body: Ruma<get_content_as_filename::v3::IncomingRequest>,
) -> Result<get_content_as_filename::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
@ -140,16 +129,16 @@ pub async fn get_content_as_filename_route(
content_disposition: _,
content_type,
file,
}) = db.media.get(&db.globals, &mxc).await?
}) = services().media.get(&mxc).await?
{
Ok(get_content_as_filename::v3::Response {
file,
content_type,
content_disposition: Some(format!("inline; filename={}", body.filename)),
})
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
let remote_content_response =
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
get_remote_content(&mxc, &body.server_name, &body.media_id).await?;
Ok(get_content_as_filename::v3::Response {
content_disposition: Some(format!("inline: filename={}", body.filename)),
@ -167,18 +156,16 @@ pub async fn get_content_as_filename_route(
///
/// - Only allows federation if `allow_remote` is true
pub async fn get_content_thumbnail_route(
db: DatabaseGuard,
body: Ruma<get_content_thumbnail::v3::IncomingRequest>,
) -> Result<get_content_thumbnail::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
if let Some(FileMeta {
content_type, file, ..
}) = db
}) = services()
.media
.get_thumbnail(
&mxc,
&db.globals,
body.width
.try_into()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?,
@ -189,11 +176,10 @@ pub async fn get_content_thumbnail_route(
.await?
{
Ok(get_content_thumbnail::v3::Response { file, content_type })
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
let get_thumbnail_response = db
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
let get_thumbnail_response = services()
.sending
.send_federation_request(
&db.globals,
&body.server_name,
get_content_thumbnail::v3::Request {
allow_remote: false,
@ -206,10 +192,9 @@ pub async fn get_content_thumbnail_route(
)
.await?;
db.media
services().media
.upload_thumbnail(
mxc,
&db.globals,
&None,
&get_thumbnail_response.content_type,
body.width.try_into().expect("all UInts are valid u32s"),