refactor well-known stuff to use proper ruma types, config types, etc
this does deprecate the original `well_known_` prefixed config options with a dedicated/proper config sub-block (`[config.well_known]`) Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
993c0102d9
commit
bfa68e7bc5
9 changed files with 134 additions and 66 deletions
|
@ -199,15 +199,13 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
|
|||
}
|
||||
|
||||
// send client well-known if specified so the client knows to reconfigure itself
|
||||
let client_discovery_info = DiscoveryInfo::new(HomeserverInfo::new(
|
||||
services()
|
||||
.globals
|
||||
.well_known_client()
|
||||
.to_owned()
|
||||
.unwrap_or_default(),
|
||||
));
|
||||
let client_discovery_info: Option<DiscoveryInfo> = services()
|
||||
.globals
|
||||
.well_known_client()
|
||||
.as_ref()
|
||||
.map(|server| DiscoveryInfo::new(HomeserverInfo::new(server.to_string())));
|
||||
|
||||
info!("{} logged in", user_id);
|
||||
info!("{user_id} logged in");
|
||||
|
||||
// home_server is deprecated but apparently must still be sent despite it being
|
||||
// deprecated over 6 years ago. initially i thought this macro was unnecessary,
|
||||
|
@ -217,13 +215,7 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
|
|||
user_id,
|
||||
access_token: token,
|
||||
device_id,
|
||||
well_known: {
|
||||
if client_discovery_info.homeserver.base_url.as_str() == "" {
|
||||
None
|
||||
} else {
|
||||
Some(client_discovery_info)
|
||||
}
|
||||
},
|
||||
well_known: client_discovery_info,
|
||||
expires_in: None,
|
||||
home_server: Some(services().globals.server_name().to_owned()),
|
||||
refresh_token: None,
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::collections::BTreeMap;
|
|||
use axum::{response::IntoResponse, Json};
|
||||
use ruma::api::client::{
|
||||
discovery::{
|
||||
discover_homeserver::{self, HomeserverInfo, SlidingSyncProxyInfo},
|
||||
discover_support::{self, Contact},
|
||||
get_supported_versions,
|
||||
},
|
||||
|
@ -57,23 +58,35 @@ pub async fn get_supported_versions_route(
|
|||
}
|
||||
|
||||
/// # `GET /.well-known/matrix/client`
|
||||
pub async fn well_known_client_route() -> Result<impl IntoResponse> {
|
||||
///
|
||||
/// Returns the .well-known URL if it is configured, otherwise returns 404.
|
||||
pub async fn well_known_client(_body: Ruma<discover_homeserver::Request>) -> Result<discover_homeserver::Response> {
|
||||
let client_url = match services().globals.well_known_client() {
|
||||
Some(url) => url.clone(),
|
||||
Some(url) => url.to_string(),
|
||||
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
|
||||
};
|
||||
|
||||
Ok(Json(serde_json::json!({
|
||||
"m.homeserver": {"base_url": client_url},
|
||||
"org.matrix.msc3575.proxy": {"url": client_url}
|
||||
})))
|
||||
Ok(discover_homeserver::Response {
|
||||
homeserver: HomeserverInfo {
|
||||
base_url: client_url.clone(),
|
||||
},
|
||||
identity_server: None,
|
||||
sliding_sync_proxy: Some(SlidingSyncProxyInfo {
|
||||
url: client_url,
|
||||
}),
|
||||
tile_server: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// # `GET /.well-known/matrix/support`
|
||||
///
|
||||
/// Server support contact and support page of a homeserver's domain.
|
||||
pub async fn well_known_support(_body: Ruma<discover_support::Request>) -> Result<discover_support::Response> {
|
||||
let support_page = services().globals.well_known_support_page().clone();
|
||||
let support_page = services()
|
||||
.globals
|
||||
.well_known_support_page()
|
||||
.as_ref()
|
||||
.map(ToString::to_string);
|
||||
|
||||
let role = services().globals.well_known_support_role().clone();
|
||||
|
||||
|
@ -120,9 +133,9 @@ pub async fn well_known_support(_body: Ruma<discover_support::Request>) -> Resul
|
|||
/// Web as a non-standard health check.
|
||||
pub async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
|
||||
let server_url = match services().globals.well_known_client() {
|
||||
Some(url) => url.clone(),
|
||||
Some(url) => url.to_string(),
|
||||
None => match services().globals.well_known_server() {
|
||||
Some(url) => url.clone(),
|
||||
Some(url) => url.to_string(),
|
||||
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue