diff --git a/src/api/client/media_legacy.rs b/src/api/client/media_legacy.rs index ab9d4de2b..d3567546e 100644 --- a/src/api/client/media_legacy.rs +++ b/src/api/client/media_legacy.rs @@ -6,15 +6,16 @@ use conduwuit::{ Err, Result, err, utils::{content_disposition::make_content_disposition, math::ruma_from_usize}, }; -use conduwuit_service::media::{CACHE_CONTROL_IMMUTABLE, CORP_CROSS_ORIGIN, Dim, FileMeta}; +use conduwuit_service::media::{CORP_CROSS_ORIGIN, Dim, FileMeta}; use reqwest::Url; use ruma::{ - Mxc, api::client::media::{ create_content, get_content, get_content_as_filename, get_content_thumbnail, get_media_config, get_media_preview, }, + assign, }; +use service::media::mxc::Mxc; use crate::{Ruma, RumaResponse, client::create_content_route}; @@ -25,9 +26,9 @@ pub(crate) async fn get_media_config_legacy_route( State(services): State, _body: Ruma, ) -> Result { - Ok(get_media_config::v3::Response { - upload_size: ruma_from_usize(services.server.config.max_request_size), - }) + Ok(get_media_config::v3::Response::new(ruma_from_usize( + services.server.config.max_request_size, + ))) } /// # `GET /_matrix/media/v1/config` @@ -153,13 +154,16 @@ pub(crate) async fn get_content_legacy_route( None, ); - Ok(get_content::v3::Response { - file: content.expect("entire file contents"), - content_type: content_type.map(Into::into), - content_disposition: Some(content_disposition), - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - }) + Ok(assign!( + get_content::v3::Response::new( + content.expect("entire file contents"), + content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), + } + )) }, | _ => if !services.globals.server_is_ours(&body.server_name) && body.allow_remote { @@ -177,13 +181,16 @@ pub(crate) async fn get_content_legacy_route( None, ); - Ok(get_content::v3::Response { - file: response.file, - content_type: response.content_type, - content_disposition: Some(content_disposition), - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - }) + Ok(assign!( + get_content::v3::Response::new( + response.file, + response.content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), + } + )) } else { Err!(Request(NotFound("Media not found."))) }, @@ -244,13 +251,15 @@ pub(crate) async fn get_content_as_filename_legacy_route( Some(&body.filename), ); - Ok(get_content_as_filename::v3::Response { - file: content.expect("entire file contents"), - content_type: content_type.map(Into::into), - content_disposition: Some(content_disposition), - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - }) + Ok(assign!(get_content_as_filename::v3::Response::new( + content.expect("entire file contents"), + content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), + } + )) }, | _ => if !services.globals.server_is_ours(&body.server_name) && body.allow_remote { @@ -268,13 +277,16 @@ pub(crate) async fn get_content_as_filename_legacy_route( None, ); - Ok(get_content_as_filename::v3::Response { - content_disposition: Some(content_disposition), - content_type: response.content_type, - file: response.file, - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - }) + Ok(assign!( + get_content_as_filename::v3::Response::new( + response.file, + response.content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), + } + )) } else { Err!(Request(NotFound("Media not found."))) }, @@ -335,13 +347,16 @@ pub(crate) async fn get_content_thumbnail_legacy_route( None, ); - Ok(get_content_thumbnail::v3::Response { - file: content.expect("entire file contents"), - content_type: content_type.map(Into::into), - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - content_disposition: Some(content_disposition), - }) + Ok(assign!( + get_content_thumbnail::v3::Response::new( + content.expect("entire file contents"), + content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + } + )) }, | _ => if !services.globals.server_is_ours(&body.server_name) && body.allow_remote { @@ -359,13 +374,16 @@ pub(crate) async fn get_content_thumbnail_legacy_route( None, ); - Ok(get_content_thumbnail::v3::Response { - file: response.file, - content_type: response.content_type, - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - content_disposition: Some(content_disposition), - }) + Ok(assign!( + get_content_thumbnail::v3::Response::new( + response.file, + response.content_type.unwrap_or_default(), + content_disposition, + ), + { + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + } + )) } else { Err!(Request(NotFound("Media not found."))) },