feat: record and show systemlog, admin delete log

This commit is contained in:
2022-03-26 02:49:18 +08:00
parent 59714bfbef
commit ce3379c5ae
5 changed files with 84 additions and 9 deletions

View File

@@ -1,16 +1,26 @@
use crate::api::{CurrentUser, API};
use crate::db_conn::Db;
use crate::api::{CurrentUser, JsonAPI};
use crate::random_hasher::RandomHasher;
use crate::rds_conn::RdsConn;
use crate::rds_models::Systemlog;
use rocket::serde::json::{json, Value};
use rocket::State;
#[get("/systemlog")]
pub async fn get_systemlog(user: CurrentUser, rh: &State<RandomHasher>, db: Db) -> API<Value> {
pub async fn get_systemlog(user: CurrentUser, rh: &State<RandomHasher>, rconn: RdsConn) -> JsonAPI {
let logs = Systemlog::get_list(&rconn, 50).await?;
Ok(json!({
"tmp_token": rh.get_tmp_token(),
"salt": look!(rh.salt),
"start_time": rh.start_time.timestamp(),
"custom_title": user.custom_title,
"data": [],
"data": logs.into_iter().map(|log|
json!({
"type": log.action_type,
"user": look!(log.user_hash),
"timestamp": log.time.timestamp(),
"detail": format!("{}\n{}", &log.target, &log.detail)
})
).collect::<Vec<Value>>(),
}))
}