add functionality to show log
This commit is contained in:
parent
cfd0ccc8c2
commit
08a1d16f88
@ -51,4 +51,16 @@ LIMIT 1000
|
||||
ret.push_str("</rss>");
|
||||
ret.replace('\n', "")
|
||||
}
|
||||
|
||||
pub async fn show(db: &SqlitePool) -> String {
|
||||
let mut ret = String::new();
|
||||
|
||||
for log in Self::last(db).await {
|
||||
let utc_time: DateTime<Utc> = Utc::from_utc_datetime(&Utc, &log.created_at);
|
||||
let local_time = utc_time.with_timezone(&Local);
|
||||
ret.push_str(&format!("- {} - {}\n", local_time, log.msg));
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,34 @@
|
||||
use rocket::{get, routes, Route, State};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{model::log::Log, tera::Config};
|
||||
use crate::{
|
||||
model::{log::Log, user::AdminUser},
|
||||
tera::Config,
|
||||
};
|
||||
|
||||
pub mod boat;
|
||||
pub mod planned_event;
|
||||
pub mod user;
|
||||
|
||||
#[get("/rss?<key>")]
|
||||
async fn rss(db: &State<SqlitePool>, key: Option<&str>, config: &State<Config>) -> String {
|
||||
match key {
|
||||
Some(key) if key.eq(&config.rss_key) => Log::generate_feed(db).await,
|
||||
_ => "Not allowed".to_string(),
|
||||
async fn rss(db: &State<SqlitePool>, key: &str, config: &State<Config>) -> String {
|
||||
if key.eq(&config.rss_key) {
|
||||
Log::generate_feed(db).await
|
||||
} else {
|
||||
"Not allowed".into()
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/rss", rank = 2)]
|
||||
async fn show_rss(db: &State<SqlitePool>, _admin: AdminUser) -> String {
|
||||
Log::show(db).await
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
let mut ret = Vec::new();
|
||||
ret.append(&mut user::routes());
|
||||
ret.append(&mut boat::routes());
|
||||
ret.append(&mut planned_event::routes());
|
||||
ret.append(&mut routes![rss]);
|
||||
ret.append(&mut routes![rss, show_rss]);
|
||||
ret
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
use rocket::{get, http::ContentType, routes, Route, State};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{planned_event::PlannedEvent, user::User};
|
||||
use crate::model::planned_event::PlannedEvent;
|
||||
|
||||
#[get("/cal")]
|
||||
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
|
||||
|
@ -4,7 +4,7 @@ use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
stat::{self, Stat},
|
||||
user::{NonGuestUser, User},
|
||||
user::NonGuestUser,
|
||||
};
|
||||
|
||||
use super::log::KioskCookie;
|
||||
|
Loading…
Reference in New Issue
Block a user