feature(relay): added route to receive transfer informations
This commit is contained in:
parent
a8de5b5335
commit
dbd571e3ad
2 changed files with 28 additions and 1 deletions
|
|
@ -16,7 +16,7 @@
|
|||
/// 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, Json, State, WebSocketUpgrade},
|
||||
extract::{ws::WebSocket, Json, Path, State, WebSocketUpgrade},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
routing::{get, post},
|
||||
|
|
@ -98,6 +98,7 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
|||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.route("/upload", post(upload_info))
|
||||
.route("/download/:name", get(download_info))
|
||||
.with_state(server)
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
|
|
@ -295,3 +296,27 @@ pub async fn upload_info(
|
|||
|
||||
(StatusCode::CREATED, Json(t_request))
|
||||
}
|
||||
|
||||
pub async fn download_info(
|
||||
State(shared_state): State<Arc<RwLock<AppState>>>,
|
||||
Path(name): Path<String>,
|
||||
) -> impl IntoResponse {
|
||||
let data = shared_state.write().await;
|
||||
match data.transfers.iter().find(|request| request.name == name) {
|
||||
Some(request) => {
|
||||
debug!("Found transfer name.");
|
||||
(StatusCode::OK, Json(request.clone()))
|
||||
}
|
||||
None => {
|
||||
warn!("couldn't find transfer-name: {}", name);
|
||||
(
|
||||
StatusCode::NOT_FOUND,
|
||||
Json(Transfer {
|
||||
name: "".to_string(),
|
||||
ip: "".to_string(),
|
||||
room_id: "".to_string(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::relay::appstate::AppState;
|
||||
use crate::relay::server::download_info;
|
||||
use crate::relay::server::upload_info;
|
||||
use crate::relay::server::ws_handler;
|
||||
use axum::{
|
||||
|
|
@ -22,6 +23,7 @@ async fn axum() -> ShuttleAxum {
|
|||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.route("/upload", post(upload_info))
|
||||
.route("/download/:name", get(download_info))
|
||||
.with_state(appstate)
|
||||
.layer(SecureClientIpSource::ConnectInfo.into_extension());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue