Format files

This commit is contained in:
Tony Klink 2024-01-26 14:15:53 -06:00
parent ecb49bf88a
commit ab9fe76494
Signed by: klink
GPG key ID: 85175567C4D19231
8 changed files with 34 additions and 34 deletions

View file

@ -3,11 +3,11 @@ use db::Noose;
use pipeline::Pipeline;
use tokio::runtime;
pub mod db;
mod migrations;
pub mod pipeline;
pub mod sled;
mod sqlite;
pub mod user;
mod migrations;
pub fn start(context: Context) {
let rt = runtime::Runtime::new().unwrap();

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use crate::bussy::{channels, Command, Message, PubSub};
use crate::utils::error::Error;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)]
pub struct BanInfo {
@ -18,10 +18,7 @@ impl SledDb {
pub fn new() -> Self {
let db = sled::open("/tmp/sled_db").unwrap();
let banned_pubkeys = db.open_tree("banned_pubkeys").unwrap();
Self {
db,
banned_pubkeys
}
Self { db, banned_pubkeys }
}
pub async fn start(&mut self, pubsub: Arc<PubSub>) -> Result<(), Error> {
@ -73,16 +70,19 @@ impl SledDb {
}
async fn ban_user(&self, ban_info: Box<BanInfo>) -> Result<bool, Error> {
if let Ok(Some(_)) = self.banned_pubkeys.insert(ban_info.pubkey, ban_info.reason.as_bytes()) {
return Ok(true)
if let Ok(Some(_)) = self
.banned_pubkeys
.insert(ban_info.pubkey, ban_info.reason.as_bytes())
{
return Ok(true);
}
Ok(false)
}
fn is_banned(&self, pubkey: &String) -> bool{
fn is_banned(&self, pubkey: &String) -> bool {
if let Ok(Some(banned)) = self.banned_pubkeys.get(pubkey) {
return true
return true;
}
false
}
@ -98,18 +98,22 @@ impl SledDb {
}
async fn get_bans(&self) -> Result<Vec<BanInfo>, Error> {
let bans: Vec<BanInfo> = self.banned_pubkeys.iter().filter_map(|row| {
if let Ok((k, v)) = row {
let ban_info = BanInfo {
pubkey: String::from_utf8(k.to_vec()).unwrap(),
reason: String::from_utf8(v.to_vec()).unwrap(),
};
let bans: Vec<BanInfo> = self
.banned_pubkeys
.iter()
.filter_map(|row| {
if let Ok((k, v)) = row {
let ban_info = BanInfo {
pubkey: String::from_utf8(k.to_vec()).unwrap(),
reason: String::from_utf8(v.to_vec()).unwrap(),
};
Some(ban_info)
} else {
None
}
}).collect();
Some(ban_info)
} else {
None
}
})
.collect();
Ok(bans)
}
@ -119,7 +123,7 @@ impl SledDb {
if let Ok(Some(reason)) = self.banned_pubkeys.get(pubkey) {
let ban_info = BanInfo {
pubkey: pubkey.to_owned(),
reason: String::from_utf8(reason.to_vec()).unwrap()
reason: String::from_utf8(reason.to_vec()).unwrap(),
};
return Ok(Some(ban_info));
@ -133,6 +137,4 @@ impl SledDb {
}
#[cfg(test)]
mod tests {
}
mod tests {}