From ab9fe76494b765d242c452b151f5ce1db524f757 Mon Sep 17 00:00:00 2001 From: Tony Klink Date: Fri, 26 Jan 2024 14:15:53 -0600 Subject: [PATCH] Format files --- src/bussy/mod.rs | 2 +- src/noose/mod.rs | 2 +- src/noose/sled.rs | 50 ++++++++++++++++--------------- src/relay/ws.rs | 4 +-- src/utils/config.rs | 4 +-- src/utils/error.rs | 2 +- src/utils/mod.rs | 2 +- src/utils/nostr_filter_helpers.rs | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/bussy/mod.rs b/src/bussy/mod.rs index 5fdfb72..e39ce40 100644 --- a/src/bussy/mod.rs +++ b/src/bussy/mod.rs @@ -1,6 +1,6 @@ use crate::{ - noose::user::{User, UserRow}, noose::sled::BanInfo, + noose::user::{User, UserRow}, utils::{error::Error, structs::Subscription}, }; use nostr::secp256k1::XOnlyPublicKey; diff --git a/src/noose/mod.rs b/src/noose/mod.rs index c97c993..8c260c0 100644 --- a/src/noose/mod.rs +++ b/src/noose/mod.rs @@ -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(); diff --git a/src/noose/sled.rs b/src/noose/sled.rs index d6b9401..9067641 100644 --- a/src/noose/sled.rs +++ b/src/noose/sled.rs @@ -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) -> Result<(), Error> { @@ -73,16 +70,19 @@ impl SledDb { } async fn ban_user(&self, ban_info: Box) -> Result { - 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, Error> { - let bans: Vec = 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 = 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 {} diff --git a/src/relay/ws.rs b/src/relay/ws.rs index 7401f21..30cd88a 100644 --- a/src/relay/ws.rs +++ b/src/relay/ws.rs @@ -262,7 +262,7 @@ async fn handle_req( client: &mut Client, subscription_id: SubscriptionId, filters: Vec, -) { +) { let subscription = Subscription::new(subscription_id.clone(), filters); let needs_historical_events = subscription.needs_historical_events(); @@ -272,7 +272,7 @@ async fn handle_req( client.ip(), &subscription_error.message ); - + let message = format!( "[\"CLOSED\", \"{}\", \"{}\"]", subscription_id, subscription_error.message diff --git a/src/utils/config.rs b/src/utils/config.rs index 287722b..3349957 100644 --- a/src/utils/config.rs +++ b/src/utils/config.rs @@ -22,9 +22,7 @@ impl Config { .unwrap() .public_key(); - let db_path = std::env::var("DATABASE_URL") - .map(PathBuf::from) - .unwrap(); + let db_path = std::env::var("DATABASE_URL").map(PathBuf::from).unwrap(); Self { admin_pubkey, diff --git a/src/utils/error.rs b/src/utils/error.rs index e50fbc5..c801287 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -1,10 +1,10 @@ use serde::{Deserialize, Serialize}; use serde_json; +use std::error::Error as StdError; use std::{ convert::From, fmt::{self, Display}, }; -use std::error::Error as StdError; use validator::ValidationErrors; use warp::{http::StatusCode, reject::Reject}; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 87a5861..9694748 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,8 +1,8 @@ +pub mod config; pub mod crypto; pub mod error; pub mod filter; mod nostr_filter_helpers; -pub mod config; pub mod rejection_handler; pub mod response; pub mod structs; diff --git a/src/utils/nostr_filter_helpers.rs b/src/utils/nostr_filter_helpers.rs index a001dc9..95c9a64 100644 --- a/src/utils/nostr_filter_helpers.rs +++ b/src/utils/nostr_filter_helpers.rs @@ -125,7 +125,7 @@ fn tag_match(filter: &Filter, event: &Event) -> bool { }) }) ); - + filter .generic_tags .iter()