add: server stats page
This commit is contained in:
parent
98d6f21e6e
commit
07f5ebf8e7
8 changed files with 97 additions and 1 deletions
|
@ -56,6 +56,7 @@ pub fn routes() -> Router {
|
|||
"/mod_panel/profile/{id}/warnings",
|
||||
get(mod_panel::manage_profile_warnings_request),
|
||||
)
|
||||
.route("/mod_panel/stats", get(mod_panel::stats_request))
|
||||
// auth
|
||||
.route("/auth/register", get(auth::register_request))
|
||||
.route("/auth/login", get(auth::login_request))
|
||||
|
|
|
@ -7,7 +7,10 @@ use axum::{
|
|||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::{Error, permissions::FinePermission, reactions::AssetType};
|
||||
use tetratto_core::{
|
||||
cache::Cache,
|
||||
model::{permissions::FinePermission, reactions::AssetType, Error},
|
||||
};
|
||||
|
||||
/// `/mod_panel/audit_log`
|
||||
pub async fn audit_log_request(
|
||||
|
@ -232,3 +235,51 @@ pub async fn manage_profile_warnings_request(
|
|||
// return
|
||||
Ok(Html(data.1.render("mod/warnings.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/mod_panel/stats`
|
||||
pub async fn stats_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
if !user.permissions.check(FinePermission::VIEW_AUDIT_LOG) {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert(
|
||||
"active_users_chats",
|
||||
&data
|
||||
.0
|
||||
.2
|
||||
.get("atto.active_connections:chats".to_string())
|
||||
.await
|
||||
.unwrap_or("0".to_string())
|
||||
.parse::<i64>()
|
||||
.unwrap(),
|
||||
);
|
||||
context.insert(
|
||||
"active_users",
|
||||
&data
|
||||
.0
|
||||
.2
|
||||
.get("atto.active_connections:users".to_string())
|
||||
.await
|
||||
.unwrap_or("0".to_string())
|
||||
.parse::<i64>()
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("mod/stats.html", &context).unwrap()))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue