ctoolbox/io/webui/controllers/
web.rs1use axum::response::IntoResponse;
4use axum::{extract::State, response::Response};
5
6use crate::io::webui::{
9 AppState, RequestState, respond_general, respond_markdown_page,
10};
11use crate::io::webui::controllers::base::{redirect_temporary};
12use crate::json_value;
13use crate::utilities::build_info;
14
15pub async fn get_index(
16 State(state): State<AppState>,
17 req: RequestState,
18) -> Response {
19 let commit = build_info().commit;
20 respond_general(&state, req, "index", &json_value!({}))
21}
22
23pub async fn privacy_policy(
24 State(state): State<AppState>,
25 req: RequestState,
26) -> Response {
27 respond_markdown_page(&state, req, "privacy-policy")
28}
29
30pub async fn subscribe(
31 State(state): State<AppState>,
32 req: RequestState,
33) -> Response {
34 redirect_temporary(req.is_js_request, "https://collectivetoolbox.eo.page/")
35}
36
37#[cfg(test)]
38mod tests {
39 use crate::io::webui::test_helpers::{
40 assert_eq_or_print_body, assert_or_print_body, test_get_no_login,
41 };
42
43 #[crate::ctb_test(tokio::test)]
44 async fn can_get_index() {
45 let (status, body) = test_get_no_login("/").await;
46 assert_eq_or_print_body(status, 200, &body);
47 assert_or_print_body(
48 body.contains("<title>Collective Toolbox</title>"),
49 &body,
50 );
51 }
52}