Merge pull request #81 from PatrykHegenberg/56-implement-a-route-to-announce-a-transfer
56 implement a route to announce a transfer
This commit is contained in:
commit
a8de5b5335
2 changed files with 31 additions and 3 deletions
|
|
@ -16,9 +16,10 @@
|
|||
/// and running the application. If the server fails to bind to the specified
|
||||
/// host and port, it logs an error and exits.
|
||||
use axum::{
|
||||
extract::{ws::WebSocket, State, WebSocketUpgrade},
|
||||
extract::{ws::WebSocket, Json, State, WebSocketUpgrade},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
routing::get,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
|
||||
|
|
@ -34,6 +35,7 @@ use tracing::{debug, error, info, warn};
|
|||
|
||||
use crate::relay::appstate::AppState;
|
||||
use crate::relay::client::Client;
|
||||
use crate::relay::transfer::Transfer;
|
||||
|
||||
/// This function starts the WebSocket server.
|
||||
///
|
||||
|
|
@ -95,6 +97,7 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
|||
// Set up the application routes.
|
||||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.route("/upload", post(upload_info))
|
||||
.with_state(server)
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
|
|
@ -272,3 +275,23 @@ async fn shutdown_signal() {
|
|||
_ = terminate => {},
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn upload_info(
|
||||
State(shared_state): State<Arc<RwLock<AppState>>>,
|
||||
// ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
Json(payload): Json<Transfer>,
|
||||
) -> impl IntoResponse {
|
||||
// debug!("Got upload request from {}", addr.ip().to_string());
|
||||
let mut data = shared_state.write().await;
|
||||
let t_request = Transfer {
|
||||
name: payload.name,
|
||||
ip: payload.ip,
|
||||
room_id: payload.room_id,
|
||||
};
|
||||
data.transfers.push(t_request.clone());
|
||||
|
||||
debug!("New TransferRequest created");
|
||||
debug!("Actual AppState is {:#?}", *data);
|
||||
|
||||
(StatusCode::CREATED, Json(t_request))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
use crate::relay::appstate::AppState;
|
||||
use crate::relay::server::upload_info;
|
||||
use crate::relay::server::ws_handler;
|
||||
use axum::{routing::get, Router};
|
||||
use axum::{
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use axum_client_ip::SecureClientIpSource;
|
||||
use shuttle_axum::ShuttleAxum;
|
||||
|
||||
|
|
@ -17,6 +21,7 @@ async fn axum() -> ShuttleAxum {
|
|||
// Set up the application routes.
|
||||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.route("/upload", post(upload_info))
|
||||
.with_state(appstate)
|
||||
.layer(SecureClientIpSource::ConnectInfo.into_extension());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue