|
|
|
@ -48,22 +48,13 @@ pub fn create_content_route( |
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "conduit_bin", |
|
|
|
feature = "conduit_bin", |
|
|
|
get( |
|
|
|
get("/_matrix/media/r0/download/<_>/<_>", data = "<body>") |
|
|
|
"/_matrix/media/r0/download/<_server_name>/<_media_id>", |
|
|
|
|
|
|
|
data = "<body>" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
)] |
|
|
|
)] |
|
|
|
pub async fn get_content_route( |
|
|
|
pub async fn get_content_route( |
|
|
|
db: State<'_, Database>, |
|
|
|
db: State<'_, Database>, |
|
|
|
body: Ruma<get_content::Request<'_>>, |
|
|
|
body: Ruma<get_content::Request<'_>>, |
|
|
|
_server_name: String, |
|
|
|
|
|
|
|
_media_id: String, |
|
|
|
|
|
|
|
) -> ConduitResult<get_content::Response> { |
|
|
|
) -> ConduitResult<get_content::Response> { |
|
|
|
let mxc = format!( |
|
|
|
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); |
|
|
|
"mxc://{}/{}", |
|
|
|
|
|
|
|
db.globals.server_name(), |
|
|
|
|
|
|
|
utils::random_string(MXC_LENGTH) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(FileMeta { |
|
|
|
if let Some(FileMeta { |
|
|
|
filename, |
|
|
|
filename, |
|
|
|
@ -77,10 +68,10 @@ pub async fn get_content_route( |
|
|
|
content_disposition: filename.unwrap_or_default(), // TODO: Spec says this should be optional
|
|
|
|
content_disposition: filename.unwrap_or_default(), // TODO: Spec says this should be optional
|
|
|
|
} |
|
|
|
} |
|
|
|
.into()) |
|
|
|
.into()) |
|
|
|
} else if body.allow_remote { |
|
|
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote { |
|
|
|
let get_content_response = server_server::send_request( |
|
|
|
let get_content_response = server_server::send_request( |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
body.server_name.as_ref(), |
|
|
|
body.server_name.clone(), |
|
|
|
get_content::Request { |
|
|
|
get_content::Request { |
|
|
|
allow_remote: false, |
|
|
|
allow_remote: false, |
|
|
|
server_name: &body.server_name, |
|
|
|
server_name: &body.server_name, |
|
|
|
@ -104,21 +95,18 @@ pub async fn get_content_route( |
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "conduit_bin", |
|
|
|
feature = "conduit_bin", |
|
|
|
get( |
|
|
|
get("/_matrix/media/r0/thumbnail/<_>/<_>", data = "<body>") |
|
|
|
"/_matrix/media/r0/thumbnail/<_server_name>/<_media_id>", |
|
|
|
|
|
|
|
data = "<body>" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
)] |
|
|
|
)] |
|
|
|
pub async fn get_content_thumbnail_route( |
|
|
|
pub async fn get_content_thumbnail_route( |
|
|
|
db: State<'_, Database>, |
|
|
|
db: State<'_, Database>, |
|
|
|
body: Ruma<get_content_thumbnail::Request<'_>>, |
|
|
|
body: Ruma<get_content_thumbnail::Request<'_>>, |
|
|
|
_server_name: String, |
|
|
|
|
|
|
|
_media_id: String, |
|
|
|
|
|
|
|
) -> ConduitResult<get_content_thumbnail::Response> { |
|
|
|
) -> ConduitResult<get_content_thumbnail::Response> { |
|
|
|
|
|
|
|
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); |
|
|
|
|
|
|
|
|
|
|
|
if let Some(FileMeta { |
|
|
|
if let Some(FileMeta { |
|
|
|
content_type, file, .. |
|
|
|
content_type, file, .. |
|
|
|
}) = db.media.get_thumbnail( |
|
|
|
}) = db.media.get_thumbnail( |
|
|
|
format!("mxc://{}/{}", body.server_name, body.media_id), |
|
|
|
mxc.clone(), |
|
|
|
body.width |
|
|
|
body.width |
|
|
|
.try_into() |
|
|
|
.try_into() |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
@ -127,10 +115,10 @@ pub async fn get_content_thumbnail_route( |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid."))?, |
|
|
|
)? { |
|
|
|
)? { |
|
|
|
Ok(get_content_thumbnail::Response { file, content_type }.into()) |
|
|
|
Ok(get_content_thumbnail::Response { file, content_type }.into()) |
|
|
|
} else if body.allow_remote { |
|
|
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote { |
|
|
|
let get_thumbnail_response = server_server::send_request( |
|
|
|
let get_thumbnail_response = server_server::send_request( |
|
|
|
&db.globals, |
|
|
|
&db.globals, |
|
|
|
body.server_name.as_ref(), |
|
|
|
body.server_name.clone(), |
|
|
|
get_content_thumbnail::Request { |
|
|
|
get_content_thumbnail::Request { |
|
|
|
allow_remote: false, |
|
|
|
allow_remote: false, |
|
|
|
height: body.height, |
|
|
|
height: body.height, |
|
|
|
@ -142,12 +130,6 @@ pub async fn get_content_thumbnail_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.await?; |
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
let mxc = format!( |
|
|
|
|
|
|
|
"mxc://{}/{}", |
|
|
|
|
|
|
|
db.globals.server_name(), |
|
|
|
|
|
|
|
utils::random_string(MXC_LENGTH) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.media.upload_thumbnail( |
|
|
|
db.media.upload_thumbnail( |
|
|
|
mxc, |
|
|
|
mxc, |
|
|
|
&None, |
|
|
|
&None, |
|
|
|
|