mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Fix errors in api/client/media_legacy.rs
Sent from my Steam Deck
This commit is contained in:
@@ -6,15 +6,16 @@ use conduwuit::{
|
|||||||
Err, Result, err,
|
Err, Result, err,
|
||||||
utils::{content_disposition::make_content_disposition, math::ruma_from_usize},
|
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 reqwest::Url;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
Mxc,
|
|
||||||
api::client::media::{
|
api::client::media::{
|
||||||
create_content, get_content, get_content_as_filename, get_content_thumbnail,
|
create_content, get_content, get_content_as_filename, get_content_thumbnail,
|
||||||
get_media_config, get_media_preview,
|
get_media_config, get_media_preview,
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
};
|
};
|
||||||
|
use service::media::mxc::Mxc;
|
||||||
|
|
||||||
use crate::{Ruma, RumaResponse, client::create_content_route};
|
use crate::{Ruma, RumaResponse, client::create_content_route};
|
||||||
|
|
||||||
@@ -25,9 +26,9 @@ pub(crate) async fn get_media_config_legacy_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
_body: Ruma<get_media_config::v3::Request>,
|
_body: Ruma<get_media_config::v3::Request>,
|
||||||
) -> Result<get_media_config::v3::Response> {
|
) -> Result<get_media_config::v3::Response> {
|
||||||
Ok(get_media_config::v3::Response {
|
Ok(get_media_config::v3::Response::new(ruma_from_usize(
|
||||||
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
services.server.config.max_request_size,
|
||||||
})
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/media/v1/config`
|
/// # `GET /_matrix/media/v1/config`
|
||||||
@@ -153,13 +154,16 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content::v3::Response {
|
Ok(assign!(
|
||||||
file: content.expect("entire file contents"),
|
get_content::v3::Response::new(
|
||||||
content_type: content_type.map(Into::into),
|
content.expect("entire file contents"),
|
||||||
content_disposition: Some(content_disposition),
|
content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
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,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content::v3::Response {
|
Ok(assign!(
|
||||||
file: response.file,
|
get_content::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
content_disposition: Some(content_disposition),
|
response.content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -244,13 +251,15 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
Some(&body.filename),
|
Some(&body.filename),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(assign!(get_content_as_filename::v3::Response::new(
|
||||||
file: content.expect("entire file contents"),
|
content.expect("entire file contents"),
|
||||||
content_type: content_type.map(Into::into),
|
content_type.unwrap_or_default(),
|
||||||
content_disposition: Some(content_disposition),
|
content_disposition,
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
{
|
||||||
})
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
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,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(assign!(
|
||||||
content_disposition: Some(content_disposition),
|
get_content_as_filename::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
file: response.file,
|
response.content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -335,13 +347,16 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_thumbnail::v3::Response {
|
Ok(assign!(
|
||||||
file: content.expect("entire file contents"),
|
get_content_thumbnail::v3::Response::new(
|
||||||
content_type: content_type.map(Into::into),
|
content.expect("entire file contents"),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_type.unwrap_or_default(),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content_disposition,
|
||||||
content_disposition: Some(content_disposition),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
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,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_thumbnail::v3::Response {
|
Ok(assign!(
|
||||||
file: response.file,
|
get_content_thumbnail::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
response.content_type.unwrap_or_default(),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content_disposition,
|
||||||
content_disposition: Some(content_disposition),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user