zmiany2
This commit is contained in:
29
src/main.rs
29
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<ChannelData>) -> 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<ChannelData>) -> 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())
|
||||
}
|
||||
|
@@ -20,7 +20,12 @@
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Utwórz</button>
|
||||
</form>
|
||||
{% if flash_message %}<div class="alert alert-success mt-3">{{ flash_message }}</div>{% endif %}
|
||||
|
||||
{% if flash_message %}
|
||||
<div class="alert alert-success">{{ flash_message }}</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<p class="mt-3">Twój IP: {{ client_ip }} | UUID: {{ client_uuid }} | Data: {{ now }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<h6>{{ graph.title }}</h6>
|
||||
<img src="/static/graphs/{{ graph.file }}" alt="{{ graph.title }}" class="img-fluid graph">
|
||||
{% endfor %}
|
||||
<p class="mt-3">Aktualny czas: {{ now }}</p>
|
||||
<p class="mt-3">Aktualny czas: {{ now_str }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user