rename to game, add 404 page
This commit is contained in:
56
src/game.rs
Normal file
56
src/game.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use crate::{client_id, page::new};
|
||||
use axum::{
|
||||
extract::Path,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use maud::{html, Markup, PreEscaped};
|
||||
use uuid::Uuid;
|
||||
|
||||
fn page(content: Markup) -> Markup {
|
||||
new(html! {
|
||||
hgroup {
|
||||
h1 { "Digital Shadows" (PreEscaped("—")) "Who finds the most cameras?" }
|
||||
(content)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn index() -> Markup {
|
||||
page(html! {})
|
||||
}
|
||||
|
||||
async fn game(cookies: CookieJar, Path(uuid): Path<String>) -> Response {
|
||||
let (cookies, device) = client_id(cookies);
|
||||
|
||||
let Ok(uuid) = Uuid::parse_str(&uuid) else {
|
||||
return not_found().await.into_response();
|
||||
};
|
||||
|
||||
let markup = new(html! {
|
||||
hgroup {
|
||||
h1 { "Digital Shadows" (PreEscaped("—")) "Who finds the most cameras?" }
|
||||
h2 {
|
||||
(device)
|
||||
" found camera "
|
||||
(uuid)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(cookies, markup).into_response()
|
||||
}
|
||||
|
||||
async fn not_found() -> Markup {
|
||||
new(html! {
|
||||
h1 { "uups" }
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn routes() -> Router {
|
||||
Router::new()
|
||||
.route("/game", get(index))
|
||||
.route("/{*uuid}", get(game))
|
||||
}
|
Reference in New Issue
Block a user