Skip to content
Snippets Groups Projects
Commit b01d2527 authored by Jason Volk's avatar Jason Volk Committed by 🥺
Browse files

fix remote media error propagation


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent b3984f53
No related branches found
No related tags found
No related merge requests found
...@@ -181,15 +181,18 @@ pub(crate) async fn get_content_route(body: Ruma<get_content::v3::Request>) -> R ...@@ -181,15 +181,18 @@ pub(crate) async fn get_content_route(body: Ruma<get_content::v3::Request>) -> R
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
}) })
} else if &*body.server_name != services().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( get_remote_content(
&mxc, &mxc,
&body.server_name, &body.server_name,
body.media_id.clone(), body.media_id.clone(),
body.allow_redirect, body.allow_redirect,
body.timeout_ms, body.timeout_ms,
) )
.await?; .await
Ok(remote_content_response) .map_err(|e| {
debug_warn!("Fetching media `{}` failed: {:?}", mxc, e);
Error::BadRequest(ErrorKind::NotFound, "Remote media error.")
})
} else { } else {
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")) Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
} }
...@@ -240,22 +243,27 @@ pub(crate) async fn get_content_as_filename_route( ...@@ -240,22 +243,27 @@ pub(crate) async fn get_content_as_filename_route(
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
}) })
} else if &*body.server_name != services().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( match get_remote_content(
&mxc, &mxc,
&body.server_name, &body.server_name,
body.media_id.clone(), body.media_id.clone(),
body.allow_redirect, body.allow_redirect,
body.timeout_ms, body.timeout_ms,
) )
.await?; .await
{
Ok(get_content_as_filename::v3::Response { Ok(remote_content_response) => Ok(get_content_as_filename::v3::Response {
content_disposition: Some(format!("inline: filename={}", body.filename)), content_disposition: Some(format!("inline: filename={}", body.filename)),
content_type: remote_content_response.content_type, content_type: remote_content_response.content_type,
file: remote_content_response.file, file: remote_content_response.file,
cross_origin_resource_policy: Some("cross-origin".to_owned()), cross_origin_resource_policy: Some("cross-origin".to_owned()),
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
}) }),
Err(e) => {
debug_warn!("Fetching media `{}` failed: {:?}", mxc, e);
Err(Error::BadRequest(ErrorKind::NotFound, "Remote media error."))
},
}
} else { } else {
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")) Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
} }
...@@ -330,7 +338,7 @@ pub(crate) async fn get_content_thumbnail_route( ...@@ -330,7 +338,7 @@ pub(crate) async fn get_content_thumbnail_route(
return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")); return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."));
} }
let get_thumbnail_response = services() match services()
.sending .sending
.send_federation_request( .send_federation_request(
&body.server_name, &body.server_name,
...@@ -345,22 +353,29 @@ pub(crate) async fn get_content_thumbnail_route( ...@@ -345,22 +353,29 @@ pub(crate) async fn get_content_thumbnail_route(
allow_redirect: body.allow_redirect, allow_redirect: body.allow_redirect,
}, },
) )
.await?; .await
{
services() Ok(get_thumbnail_response) => {
.media services()
.upload_thumbnail( .media
None, .upload_thumbnail(
mxc, None,
None, mxc,
get_thumbnail_response.content_type.as_deref(), None,
body.width.try_into().expect("all UInts are valid u32s"), get_thumbnail_response.content_type.as_deref(),
body.height.try_into().expect("all UInts are valid u32s"), body.width.try_into().expect("all UInts are valid u32s"),
&get_thumbnail_response.file, body.height.try_into().expect("all UInts are valid u32s"),
) &get_thumbnail_response.file,
.await?; )
.await?;
Ok(get_thumbnail_response)
Ok(get_thumbnail_response)
},
Err(e) => {
debug_warn!("Fetching media `{}` failed: {:?}", mxc, e);
Err(Error::BadRequest(ErrorKind::NotFound, "Remote media error."))
},
}
} else { } else {
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")) Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment