about to glorp

This commit is contained in:
Rakarake 2026-03-28 15:51:59 +01:00
parent 30119b1b2f
commit 32a2c63a4e
3 changed files with 158 additions and 7 deletions

View file

@ -1,9 +1,15 @@
use std::{env::{args, var}, io};
use std::{env::{args, var}, io, sync::Arc};
use axum::{Router, body::{Body, Bytes}, extract::{DefaultBodyLimit, Path}, routing::{delete, post, put}};
use axum::{Router, body::{Body, Bytes}, extract::{DefaultBodyLimit, Path, State}, routing::{delete, post, put}};
use std::path::PathBuf;
const MAXIMUM_PACKET_SIZE: usize = (2 << 20) * 10;
#[derive(Clone)]
struct AppState {
root: PathBuf,
}
#[tokio::main]
async fn main() -> io::Result<()> {
// get secret from secret file
@ -16,11 +22,15 @@ async fn main() -> io::Result<()> {
port_str.parse::<u16>().expect("PORT is malformed")
} else { 3236 };
let state = Arc::new(AppState { root: PathBuf::from(target_path) });
let app = Router::new()
.route("/", put(put_file))
.route("/", delete(delete_file))
.route("/{*key}", put(put_file))
.route("/{*key}", delete(delete_file))
.with_state(state)
.layer(DefaultBodyLimit::max(MAXIMUM_PACKET_SIZE));
let listener = tokio::net::TcpListener::bind(("localhost", port))
.await
.expect("failed to bind to tcp socket");
@ -29,11 +39,12 @@ async fn main() -> io::Result<()> {
Ok(())
}
async fn delete_file(Path(path): Path<String>) {
println!("the path: {path}");
async fn delete_file(State(state): State<Arc<AppState>>, Path(path): Path<String>) {
println!("about to delete: {path}");
}
async fn put_file(body: Bytes) {
async fn put_file(State(state): State<Arc<AppState>>, Path(path): Path<String>, body: Bytes) {
println!("about to put: {path}");
let bytes = Vec::from(body);
println!("body: {:?}", bytes);
}