Merge branch 'media-download-followup' into 'next'

Media download followup

See merge request famedly/conduit!271
This commit is contained in:
Timo Kösters 2022-01-27 16:24:15 +00:00
commit 20006c91af

View file

@ -78,8 +78,8 @@ pub async fn get_remote_content(
db: &DatabaseGuard, db: &DatabaseGuard,
mxc: &str, mxc: &str,
server_name: &ruma::ServerName, server_name: &ruma::ServerName,
media_id: &str media_id: &str,
) -> ConduitResult<get_content::Response> { ) -> Result<get_content::Response, Error> {
let content_response = db let content_response = db
.sending .sending
.send_federation_request( .send_federation_request(
@ -88,7 +88,7 @@ pub async fn get_remote_content(
get_content::Request { get_content::Request {
allow_remote: false, allow_remote: false,
server_name, server_name,
media_id media_id,
}, },
) )
.await?; .await?;
@ -103,7 +103,7 @@ pub async fn get_remote_content(
) )
.await?; .await?;
Ok(content_response.into()) Ok(content_response)
} }
/// # `GET /_matrix/media/r0/download/{serverName}/{mediaId}` /// # `GET /_matrix/media/r0/download/{serverName}/{mediaId}`
@ -135,13 +135,9 @@ pub async fn get_content_route(
} }
.into()) .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 remote_content_response = get_remote_content( let remote_content_response =
&db, get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
&mxc, Ok(remote_content_response.into())
&body.server_name,
&body.media_id
).await?;
Ok(remote_content_response)
} else { } else {
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")) Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
} }
@ -176,17 +172,13 @@ pub async fn get_content_as_filename_route(
} }
.into()) .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 remote_content_response = get_remote_content( let remote_content_response =
&db, get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
&mxc,
&body.server_name,
&body.media_id
).await?;
Ok(get_content_as_filename::Response { Ok(get_content_as_filename::Response {
content_disposition: Some(format!("inline: filename={}", body.filename)), content_disposition: Some(format!("inline: filename={}", body.filename)),
content_type: remote_content_response.0.content_type, content_type: remote_content_response.content_type,
file: remote_content_response.0.file file: remote_content_response.file,
} }
.into()) .into())
} else { } else {