move routes into api router top level

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-14 23:46:03 +00:00
parent c42cb90dd3
commit 720fbd09c2
4 changed files with 31 additions and 30 deletions

View file

@ -1,15 +1,14 @@
pub mod client;
mod router;
pub mod routes;
pub mod router;
pub mod server;
extern crate conduit_core as conduit;
extern crate conduit_service as service;
pub(crate) use conduit::{debug_info, debug_warn, utils, Error, Result};
pub(crate) use service::{pdu::PduEvent, services, user_is_local};
pub(crate) use conduit::{debug_info, debug_warn, pdu::PduEvent, utils, Error, Result};
pub(crate) use service::{services, user_is_local};
pub(crate) use self::router::{Ruma, RumaResponse};
pub(crate) use crate::router::{Ruma, RumaResponse};
conduit::mod_ctor! {}
conduit::mod_dtor! {}

View file

@ -1,3 +1,9 @@
mod args;
mod auth;
mod handler;
mod request;
mod response;
use axum::{
response::IntoResponse,
routing::{any, get, post},
@ -7,7 +13,9 @@ use conduit::{err, Error, Server};
use http::Uri;
use ruma::api::client::error::ErrorKind;
use crate::{client, router::RouterExt, server};
use self::handler::RouterExt;
pub(super) use self::{ar::Ruma, response::RumaResponse};
use crate::{client, server};
pub fn build(router: Router, server: &Server) -> Router {
let config = &server.config;
@ -95,7 +103,7 @@ pub fn build(router: Router, server: &Server) -> Router {
.ruma_route(client::get_member_events_route)
.ruma_route(client::get_protocols_route)
.route("/_matrix/client/unstable/thirdparty/protocols",
get(client::get_protocols_route_unstable))
get(client::get_protocols_route_unstable))
.ruma_route(client::send_message_event_route)
.ruma_route(client::send_state_event_for_key_route)
.ruma_route(client::get_state_events_route)
@ -180,15 +188,15 @@ pub fn build(router: Router, server: &Server) -> Router {
.ruma_route(client::get_relating_events_with_rel_type_route)
.ruma_route(client::get_relating_events_route)
.ruma_route(client::get_hierarchy_route)
.ruma_route(client::get_mutual_rooms_route)
.ruma_route(client::get_room_summary)
.route(
"/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary",
get(client::get_room_summary_legacy)
)
.ruma_route(client::well_known_support)
.ruma_route(client::well_known_client)
.route("/_conduwuit/server_version", get(client::conduwuit_server_version))
.ruma_route(client::get_mutual_rooms_route)
.ruma_route(client::get_room_summary)
.route(
"/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary",
get(client::get_room_summary_legacy)
)
.ruma_route(client::well_known_support)
.ruma_route(client::well_known_client)
.route("/_conduwuit/server_version", get(client::conduwuit_server_version))
.route("/_matrix/client/r0/rooms/:room_id/initialSync", get(initial_sync))
.route("/_matrix/client/v3/rooms/:room_id/initialSync", get(initial_sync))
.route("/client/server.json", get(client::syncv3_client_server_json));
@ -233,7 +241,7 @@ pub fn build(router: Router, server: &Server) -> Router {
}
async fn initial_sync(_uri: Uri) -> impl IntoResponse {
Error::BadRequest(ErrorKind::GuestAccessForbidden, "Guest access not implemented")
err!(Request(GuestAccessForbidden("Guest access not implemented")))
}
async fn federation_disabled() -> impl IntoResponse { err!(Config("allow_federation", "Federation is disabled.")) }

View file

@ -1,24 +1,18 @@
mod auth;
mod handler;
mod request;
mod response;
use std::{mem, ops::Deref};
use axum::{async_trait, body::Body, extract::FromRequest};
use bytes::{BufMut, BytesMut};
use conduit::{debug, debug_warn, trace, warn};
use conduit::{debug, debug_warn, trace, warn, Error, Result};
use ruma::{
api::{client::error::ErrorKind, IncomingRequest},
CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId,
};
use self::{auth::Auth, request::Request};
pub(super) use self::{handler::RouterExt, response::RumaResponse};
use crate::{service::appservice::RegistrationInfo, services, Error, Result};
use super::{auth, auth::Auth, request, request::Request};
use crate::{service::appservice::RegistrationInfo, services};
/// Extractor for Ruma request structs
pub(crate) struct Ruma<T> {
pub(crate) struct Args<T> {
/// Request struct body
pub(crate) body: T,
@ -44,7 +38,7 @@ pub(crate) struct Ruma<T> {
}
#[async_trait]
impl<T, S> FromRequest<S, Body> for Ruma<T>
impl<T, S> FromRequest<S, Body> for Args<T>
where
T: IncomingRequest,
{
@ -65,7 +59,7 @@ where
}
}
impl<T> Deref for Ruma<T> {
impl<T> Deref for Args<T> {
type Target = T;
fn deref(&self) -> &Self::Target { &self.body }

View file

@ -10,7 +10,7 @@ extern crate conduit_api as api;
pub(crate) fn build(server: &Arc<Server>) -> Router {
let state = service::services();
let router = Router::new()
api::router::build(Router::new(), server)
.route("/", get(it_works))
.fallback(not_found)
.with_state(state);