use axum::{ response::{IntoResponse, Redirect, Response}, routing::get, Router }; use crate::{ public::console, types::{ extract::{AuthorizedUser, Log, UserAgent}, http::ResponseCode, }, }; use super::docs; async fn root(user: Option, _: Log) -> Response { if user.is_some() { Redirect::to("/home").into_response() } else { Redirect::to("/login").into_response() } } async fn login(user: Option, _: Log) -> Response { if user.is_some() { Redirect::to("/home").into_response() } else { super::serve("/login.html").await } } async fn home(_: Log) -> Response { super::serve("/home.html").await } async fn people(_: Log) -> Response { super::serve("/people.html").await } async fn profile(_: Log) -> Response { super::serve("/profile.html").await } async fn console() -> Response { console::generate().await } async fn admin() -> Response { super::serve("/admin.html").await } async fn api() -> Response { docs::generate().await } async fn wordpress(_: Log) -> Response { ResponseCode::ImATeapot.text("Hello i am a teapot owo") } async fn forgot(UserAgent(agent): UserAgent, _: Log) -> Response { if agent.starts_with("curl") { return super::serve("/404.html").await } Redirect::to("https://www.youtube.com/watch?v=dQw4w9WgXcQ").into_response() } pub fn router() -> Router { Router::new() .route("/", get(root)) .route("/login", get(login)) .route("/home", get(home)) .route("/people", get(people)) .route("/profile", get(profile)) .route("/console", get(console)) .route("/wp-admin", get(wordpress)) .route("/admin", get(admin)) .route("/docs", get(api)) .route("/forgot", get(forgot)) }