diff --git a/src/main.rs b/src/main.rs index 647b793..8f88514 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ async fn main() -> anyhow::Result<()> { }); let router = Router::default() + .route("/", get(routes::root)) .route("/i/:id", get(routes::i)) .route("/i/:id", delete(routes::delete)) .route("/api/upload", post(routes::upload)) diff --git a/src/routes/mod.rs b/src/routes/mod.rs index e168903..ee15b25 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,9 +1,11 @@ mod delete; mod i; mod new_key; +mod root; mod upload; pub use delete::delete; pub use i::get as i; pub use new_key::post as new_key; +pub use root::get as root; pub use upload::post as upload; diff --git a/src/routes/root.rs b/src/routes/root.rs new file mode 100644 index 0000000..5d8d991 --- /dev/null +++ b/src/routes/root.rs @@ -0,0 +1,14 @@ +use crate::state::ReqState; +use axum::{extract::State, response::IntoResponse}; +use hyper::StatusCode; + +pub async fn get(State(state): ReqState) -> impl IntoResponse { + let file_count = state.files_dir.read_dir(); + + if file_count.is_err() { + return Err(StatusCode::INTERNAL_SERVER_ERROR); + } + + let file_count = file_count.unwrap().count(); + Ok("u".repeat(file_count).into_response()) +}