diff --git a/src/main.rs b/src/main.rs index 8d70876..025ebc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,9 @@ struct CreateTemplate<'a> { ts3_server_port: u16, client_ip: &'a str, client_uuid: &'a str, + now: &'a str, year: i32, - flash_message: Option<&'a str>, + flash_message: &'a str, // Zawsze string! pusty lub z komunikatem. } #[derive(Template)] @@ -37,6 +38,7 @@ struct StatsTemplate<'a> { graphs: &'a [Graph], last_update: &'a str, server_name: &'a str, + now: &'a str, year: i32, } @@ -54,7 +56,6 @@ async fn create_handler(data: web::Json) -> HttpResponse { } }; - // Pobierz client_info jak w app.py[1] let client_info = get_client_info(&mut stream, "127.0.0.1"); let (client_uuid, client_dbid, client_clid) = match &client_info { Some(info) => (info.uid.as_str(), info.dbid, info.clid), @@ -70,17 +71,21 @@ async fn create_handler(data: web::Json) -> HttpResponse { client_clid, ); let flash_message = match result { - Ok(_) => Some("Kanał utworzony pomyślnie"), - Err(_e) => Some("Błąd tworzenia kanału"), + Ok(_) => "Kanał utworzony pomyślnie", + Err(_e) => "Błąd tworzenia kanału", }; - let now = Utc::now(); + let now_dt = Utc::now(); + let now_str = now_dt.format("%Y-%m-%d %H:%M:%S").to_string(); + let year = now_dt.year(); + let template = CreateTemplate { ts3_server: &config.ts3_server, ts3_server_port: config.ts3_query_port, client_ip: "127.0.0.1", client_uuid, - year: now.year(), + now: &now_str, + year, flash_message, }; HttpResponse::Ok().content_type("text/html").body(template.render().unwrap()) @@ -95,13 +100,17 @@ async fn stats_handler() -> HttpResponse { Graph { file: "72h.gif".to_string(), title: "Ostatnie 72 godziny".to_string() }, Graph { file: "week.gif".to_string(), title: "Ostatni tydzień".to_string() }, ]; - let now = Utc::now(); - let last_update = now.format("%Y-%m-%d %H:%M:%S").to_string(); + let now_dt = Utc::now(); + let now_str = now_dt.format("%Y-%m-%d %H:%M:%S").to_string(); + let year = now_dt.year(); + let last_update = &now_str; + let template = StatsTemplate { graphs: &graphs, - last_update: &last_update, + last_update, server_name: "linuxiarz.pl", - year: now.year(), + now: &now_str, + year, }; HttpResponse::Ok().content_type("text/html").body(template.render().unwrap()) } diff --git a/templates/create.html b/templates/create.html index 7c85547..e821d19 100644 --- a/templates/create.html +++ b/templates/create.html @@ -20,7 +20,12 @@ - {% if flash_message %}
{{ flash_message }}
{% endif %} + +{% if flash_message %} +
{{ flash_message }}
+{% endif %} + +

Twój IP: {{ client_ip }} | UUID: {{ client_uuid }} | Data: {{ now }}

diff --git a/templates/stats.html b/templates/stats.html index 53747e5..7544294 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -10,7 +10,7 @@
{{ graph.title }}
{{ graph.title }} {% endfor %} -

Aktualny czas: {{ now }}

+

Aktualny czas: {{ now_str }}

{% endblock %}