mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 13:01:12 +03:00
Code refactored + new API
Added ability to send messages to a websocket session via HTTP API
This commit is contained in:
parent
ca6990c5b1
commit
81ab2ba724
11 changed files with 172 additions and 74 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -4,7 +4,7 @@ use axum::{
|
|||
};
|
||||
use dashmap::DashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{broadcast, Mutex};
|
||||
use tokio::sync::{broadcast, mpsc, Mutex};
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::info;
|
||||
use uuid::Uuid;
|
||||
|
|
@ -35,12 +35,10 @@ use config::Config;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppState {
|
||||
/// Users with incomplete authentication
|
||||
//pending: Arc<DashMap<String, String>>, // <SHA1 serverId, USERNAME>
|
||||
/// Authenticated users
|
||||
//authenticated: Arc<Authenticated>, // <SHA1 serverId, Userinfo> NOTE: In the future, try it in a separate LockRw branch
|
||||
/// User manager
|
||||
user_manager: Arc<UManager>,
|
||||
/// Send into WebSocket
|
||||
session: Arc<DashMap<Uuid, mpsc::Sender<Vec<u8>>>>,
|
||||
/// Ping broadcasts for WebSocket connections
|
||||
broadcasts: Arc<DashMap<Uuid, broadcast::Sender<Vec<u8>>>>,
|
||||
/// Current configuration
|
||||
|
|
@ -73,6 +71,7 @@ async fn main() -> Result<()> {
|
|||
// State
|
||||
let state = AppState {
|
||||
user_manager: Arc::new(UManager::new()),
|
||||
session: Arc::new(DashMap::new()),
|
||||
broadcasts: Arc::new(DashMap::new()),
|
||||
config: config,
|
||||
};
|
||||
|
|
@ -97,6 +96,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
let api = Router::new()
|
||||
.nest("//auth", api_auth::router())
|
||||
.nest("/v1", ws::http_router())
|
||||
.route("/limits", get(api_info::limits))
|
||||
.route("/version", get(api_info::version))
|
||||
.route("/motd", get(api_info::motd))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue