add / route

This commit is contained in:
Julian 2023-04-28 15:03:11 -04:00
parent 164811388f
commit 71825744da
Signed by: NotNite
GPG Key ID: BD91A5402CCEB08A
3 changed files with 17 additions and 0 deletions

View File

@ -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))

View File

@ -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;

14
src/routes/root.rs Normal file
View File

@ -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())
}