skeleton
This commit is contained in:
parent
ac5cba1c4d
commit
30119b1b2f
5 changed files with 566 additions and 1 deletions
8
mdf-bouncer/Cargo.toml
Normal file
8
mdf-bouncer/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "mdf-bouncer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
axum = "*"
|
||||
tokio = { version = "*", features = ["full"] }
|
||||
40
mdf-bouncer/src/main.rs
Normal file
40
mdf-bouncer/src/main.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use std::{env::{args, var}, io};
|
||||
|
||||
use axum::{Router, body::{Body, Bytes}, extract::{DefaultBodyLimit, Path}, routing::{delete, post, put}};
|
||||
|
||||
const MAXIMUM_PACKET_SIZE: usize = (2 << 20) * 10;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
// get secret from secret file
|
||||
let mut args = args().skip(1);
|
||||
let target_path = args.next().expect("need to specify target path");
|
||||
let secret_path = args.next().expect("need to specify path to secret file");
|
||||
let secret = std::fs::read_to_string(secret_path)?;
|
||||
|
||||
let port = if let Ok(port_str) = var("MDFBOUNCER_PORT") {
|
||||
port_str.parse::<u16>().expect("PORT is malformed")
|
||||
} else { 3236 };
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", put(put_file))
|
||||
.route("/", delete(delete_file))
|
||||
.layer(DefaultBodyLimit::max(MAXIMUM_PACKET_SIZE));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(("localhost", port))
|
||||
.await
|
||||
.expect("failed to bind to tcp socket");
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_file(Path(path): Path<String>) {
|
||||
println!("the path: {path}");
|
||||
}
|
||||
|
||||
async fn put_file(body: Bytes) {
|
||||
let bytes = Vec::from(body);
|
||||
println!("body: {:?}", bytes);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue