diff --git a/Cargo.toml b/Cargo.toml index 48a09c1..ff25a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ license = "Apache-2.0" [dependencies] axum = { version = "0.7", optional = true} -axum-extra = { version = "0.9", optional = true, features = ["typed-header"]} http-serde = "2.1" reqwest = { version = "0.12", features = ["rustls-tls", "stream"], default-features = false } clap = { version = "4.5", features = ["derive", "env"] } @@ -23,7 +22,7 @@ anyhow = "1" base64 = "0.22" [features] -server = ["dep:axum", "dep:axum-extra"] +server = ["dep:axum"] [profile.release] lto = true diff --git a/src/config.rs b/src/config.rs index d36f5fb..97d570a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,10 +44,6 @@ pub enum Mode { /// Address the server should bind to #[clap(env, long, default_value = "0.0.0.0:8080")] bind_addr: std::net::SocketAddr, - - /// Api key required for uploading files - #[clap(env, long)] - api_key: String, } } diff --git a/src/main.rs b/src/main.rs index 4b7d8e4..475e5b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,7 @@ async fn main() -> ExitCode { .map(Ok) .boxed(), #[cfg(feature = "server")] - Mode::Server { bind_addr, api_key } => server::serve(bind_addr, api_key).boxed(), + Mode::Server { bind_addr } => server::serve(bind_addr).boxed(), }; let result = tokio::select! { res = work => res, diff --git a/src/server.rs b/src/server.rs index 7cfb096..1d0883b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,36 +1,27 @@ -use std::{net::SocketAddr, sync::Arc}; +use std::net::SocketAddr; use axum::{ - extract::{Path, State}, http::{HeaderMap, StatusCode}, routing::post, Router + extract::Path, http::{HeaderMap, StatusCode}, routing::post, Router }; -use axum_extra::{headers::{authorization, Authorization}, TypedHeader}; use beam_lib::{AppId, MsgId, RawString, TaskRequest}; use tokio::net::TcpListener; use crate::{FileMeta, BEAM_CLIENT, CONFIG}; -pub async fn serve(addr: &SocketAddr, api_key: &str) -> anyhow::Result<()> { +pub async fn serve(addr: &SocketAddr) -> anyhow::Result<()> { let app = Router::new() - .route("/send/:to", post(send_file)) - .with_state(Arc::from(api_key)); + .route("/send/:to", post(send_file)); axum::serve(TcpListener::bind(&addr).await? ,app.into_make_service()) .with_graceful_shutdown(async { tokio::signal::ctrl_c().await.unwrap() }) .await?; Ok(()) } -type AppState = Arc; - async fn send_file( Path(other_proxy_name): Path, - auth: TypedHeader>, headers: HeaderMap, - State(api_key): State, req: String, ) -> Result<(), StatusCode> { - if auth.password() != api_key.as_ref() { - return Err(StatusCode::UNAUTHORIZED); - } let to = AppId::new_unchecked(format!( "{other_proxy_name}.{}", CONFIG.beam_id.as_ref().splitn(3, '.').nth(2).expect("Invalid app id")