From 8ec1610b2e8e08a9af76cc086b544e8fc68a6501 Mon Sep 17 00:00:00 2001 From: Radical Date: Sun, 20 Jul 2025 18:11:31 +0200 Subject: [PATCH] feat: remove dependency on socket.io Keeping stuff commented so we can revisit, currently just need a working version --- Cargo.toml | 4 ++-- src/api/v1/auth/revoke.rs | 1 - src/api/v1/channels/mod.rs | 15 +++++++++------ src/main.rs | 17 +++++------------ 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0c83bb..3decea6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,10 +38,10 @@ bindet = "0.3.2" bunny-api-tokio = { version = "0.4", features = ["edge_storage"], default-features = false } # Web Server -axum = { version = "0.8.4", features = ["macros", "multipart", "ws"] } +axum = { version = "0.8.4", features = ["multipart", "ws"] } tower-http = { version = "0.6.6", features = ["cors"] } axum-extra = { version = "0.10.1", features = ["cookie", "typed-header"] } -socketioxide = { version = "0.17.2", features = ["state"] } +#socketioxide = { version = "0.17.2", features = ["state"] } url = { version = "2.5", features = ["serde"] } time = "0.3.41" diff --git a/src/api/v1/auth/revoke.rs b/src/api/v1/auth/revoke.rs index dd87ec3..90b96ae 100644 --- a/src/api/v1/auth/revoke.rs +++ b/src/api/v1/auth/revoke.rs @@ -24,7 +24,6 @@ pub struct RevokeRequest { } // TODO: Should maybe be a delete request? -#[axum::debug_handler] pub async fn post( State(app_state): State>, Extension(CurrentUser(uuid)): Extension>, diff --git a/src/api/v1/channels/mod.rs b/src/api/v1/channels/mod.rs index cc033af..41d029a 100644 --- a/src/api/v1/channels/mod.rs +++ b/src/api/v1/channels/mod.rs @@ -1,20 +1,23 @@ use std::sync::Arc; use axum::{ - Router, - routing::{any, delete, get, patch}, + middleware::from_fn_with_state, routing::{any, delete, get, patch}, Router }; //use socketioxide::SocketIo; -use crate::AppState; +use crate::{api::v1::auth::CurrentUser, AppState}; mod uuid; -pub fn router() -> Router> { - Router::new() +pub fn router(app_state: Arc) -> Router> { + let router_with_auth = Router::new() .route("/{uuid}", get(uuid::get)) .route("/{uuid}", delete(uuid::delete)) .route("/{uuid}", patch(uuid::patch)) - .route("/{uuid}/socket", any(uuid::socket::ws)) .route("/{uuid}/messages", get(uuid::messages::get)) + .layer(from_fn_with_state(app_state, CurrentUser::check_auth_layer)); + + Router::new() + .route("/{uuid}/socket", any(uuid::socket::ws)) + .merge(router_with_auth) } diff --git a/src/main.rs b/src/main.rs index e42c8dc..13e661d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ use diesel_async::pooled_connection::deadpool::Pool; use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations}; use error::Error; use objects::MailClient; -use socketioxide::SocketIo; use std::{sync::Arc, time::SystemTime}; use tower_http::cors::{AllowOrigin, CorsLayer}; @@ -24,7 +23,7 @@ mod config; pub mod error; pub mod objects; pub mod schema; -mod socket; +//mod socket; pub mod utils; mod wordlist; @@ -53,12 +52,6 @@ pub struct AppState { async fn main() -> Result<(), Error> { tracing_subscriber::fmt::init(); - //SimpleLogger::new() - // .with_level(log::LevelFilter::Info) - // .with_colors(true) - // .env() - // .init() - // .unwrap(); let args = Args::parse(); let config = ConfigBuilder::load(args.config).await?.build(); @@ -158,12 +151,12 @@ async fn main() -> Result<(), Error> { // Allow credentials .allow_credentials(true); - let (socket_io, io) = SocketIo::builder() + /*let (socket_io, io) = SocketIo::builder() .with_state(app_state.clone()) .build_layer(); io.ns("/", socket::on_connect); - + */ // build our application with a route let app = Router::new() // `GET /` goes to `root` @@ -172,8 +165,8 @@ async fn main() -> Result<(), Error> { app_state.clone(), )) .with_state(app_state) - .layer(cors) - .layer(socket_io); + //.layer(socket_io) + .layer(cors); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind(web.ip + ":" + &web.port.to_string()).await?;