diff options
Diffstat (limited to 'server/src/routes/ui/admin')
-rw-r--r-- | server/src/routes/ui/admin/log.rs | 28 | ||||
-rw-r--r-- | server/src/routes/ui/admin/mod.rs | 12 | ||||
-rw-r--r-- | server/src/routes/ui/admin/user.rs | 4 |
3 files changed, 17 insertions, 27 deletions
diff --git a/server/src/routes/ui/admin/log.rs b/server/src/routes/ui/admin/log.rs index 5b81a52..884ad7a 100644 --- a/server/src/routes/ui/admin/log.rs +++ b/server/src/routes/ui/admin/log.rs @@ -22,7 +22,7 @@ use std::{ const MAX_LOG_LEN: usize = 4096; -static LOGGER: LazyLock<Log> = LazyLock::new(Log::new); +static LOGGER: LazyLock<Log> = LazyLock::new(Log::default); pub fn enable_logging() { log::set_logger(&*LOGGER).unwrap(); @@ -63,9 +63,8 @@ pub fn r_admin_log<'a>(_session: AdminSession, warnonly: bool) -> MyResult<DynLa ..Default::default() }) } - -impl Log { - pub fn new() -> Self { +impl Default for Log { + fn default() -> Self { Self { inner: env_logger::builder() .filter_level(log::LevelFilter::Warn) @@ -74,6 +73,8 @@ impl Log { log: Default::default(), } } +} +impl Log { fn should_log(&self, metadata: &log::Metadata) -> bool { let level = metadata.level(); level @@ -152,18 +153,11 @@ fn format_level(level: Level) -> impl markup::Render { markup::new! { span[style=format!("color:{c}")] {@s} } } +#[derive(Default)] pub struct HtmlOut { s: String, color: bool, } -impl Default for HtmlOut { - fn default() -> Self { - Self { - color: false, - s: String::new(), - } - } -} impl HtmlOut { pub fn set_color(&mut self, [r, g, b]: [u8; 3]) { self.reset_color(); @@ -184,16 +178,12 @@ impl vte::Perform for HtmlOut { x => write!(self.s, "&#{};", x as u32).unwrap(), } } - fn execute(&mut self, _byte: u8) {} fn hook(&mut self, _params: &vte::Params, _i: &[u8], _ignore: bool, _a: char) {} fn put(&mut self, _byte: u8) {} fn unhook(&mut self) {} fn osc_dispatch(&mut self, _params: &[&[u8]], _bell_terminated: bool) {} - fn esc_dispatch(&mut self, _intermediates: &[u8], _ignore: bool, _byte: u8) { - // self.s += &format!(" {:?} ", (_intermediates, _byte)) - } - + fn esc_dispatch(&mut self, _intermediates: &[u8], _ignore: bool, _byte: u8) {} fn csi_dispatch( &mut self, params: &vte::Params, @@ -202,9 +192,9 @@ impl vte::Perform for HtmlOut { action: char, ) { let mut k = params.iter(); - // self.s += &format!(" {:?} ", (params, action)); + #[allow(clippy::single_match)] match action { - 'm' => match k.next().unwrap_or(&[0]).get(0).unwrap_or(&0) { + 'm' => match k.next().unwrap_or(&[0]).first().unwrap_or(&0) { c @ (30..=37 | 40..=47) => { let c = if *c >= 40 { *c - 10 } else { *c }; self.set_color(match c { diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index 540ac72..25f1f42 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -134,7 +134,7 @@ pub async fn r_admin_invite( database: &State<DataAcid>, ) -> MyResult<DynLayoutPage<'static>> { let i = format!("{}", rand::thread_rng().gen::<u128>()); - T_INVITE.insert(&database, &*i, ())?; + T_INVITE.insert(database, &*i, ())?; admin_dashboard(database, Some(Ok(format!("Invite: {}", i)))).await } @@ -152,7 +152,7 @@ pub async fn r_admin_remove_invite( ) -> MyResult<DynLayoutPage<'static>> { drop(session); T_INVITE - .remove(&database, form.invite.as_str())? + .remove(database, form.invite.as_str())? .ok_or(anyhow!("invite did not exist"))?; admin_dashboard(database, Some(Ok("Invite invalidated".into()))).await @@ -166,9 +166,9 @@ pub async fn r_admin_import( ) -> MyResult<DynLayoutPage<'static>> { drop(session); let t = Instant::now(); - let r = import(&database, &federation).await; + let r = import(database, federation).await; admin_dashboard( - &database, + database, Some( r.map_err(|e| e.into()) .map(|_| format!("Import successful; took {:?}", t.elapsed())), @@ -187,7 +187,7 @@ pub async fn r_admin_delete_cache( let r = tokio::fs::remove_dir_all(&CONF.cache_path).await; tokio::fs::create_dir(&CONF.cache_path).await?; admin_dashboard( - &database, + database, Some( r.map_err(|e| e.into()) .map(|_| format!("Cache deleted; took {:?}", t.elapsed())), @@ -233,7 +233,7 @@ pub async fn r_admin_transcode_posters( drop(_permit); admin_dashboard( - &database, + database, Some(Ok(format!( "All posters pre-transcoded; took {:?}", t.elapsed() diff --git a/server/src/routes/ui/admin/user.rs b/server/src/routes/ui/admin/user.rs index 4d77191..26c1837 100644 --- a/server/src/routes/ui/admin/user.rs +++ b/server/src/routes/ui/admin/user.rs @@ -76,7 +76,7 @@ fn manage_single_user<'a>( name: String, ) -> MyResult<DynLayoutPage<'a>> { let user = T_USER - .get(&database, &*name)? + .get(database, &*name)? .ok_or(anyhow!("user does not exist"))?; let flash = flash.map(|f| f.map_err(|e| format!("{e:?}"))); @@ -193,7 +193,7 @@ pub fn r_admin_remove_user( ) -> MyResult<DynLayoutPage<'static>> { drop(session); T_USER - .remove(&database, form.name.as_str())? + .remove(database, form.name.as_str())? .ok_or(anyhow!("user did not exist"))?; user_management(database, Some(Ok("User removed".into()))) } |