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

@ -1,6 +1,6 @@
use crate::{ use crate::{
noose::user::{User, UserRow},
noose::sled::BanInfo, noose::sled::BanInfo,
noose::user::{User, UserRow},
utils::{error::Error, structs::Subscription}, utils::{error::Error, structs::Subscription},
}; };
use nostr::secp256k1::XOnlyPublicKey; use nostr::secp256k1::XOnlyPublicKey;

View file

@ -3,11 +3,11 @@ use db::Noose;
use pipeline::Pipeline; use pipeline::Pipeline;
use tokio::runtime; use tokio::runtime;
pub mod db; pub mod db;
mod migrations;
pub mod pipeline; pub mod pipeline;
pub mod sled; pub mod sled;
mod sqlite; mod sqlite;
pub mod user; pub mod user;
mod migrations;
pub fn start(context: Context) { pub fn start(context: Context) {
let rt = runtime::Runtime::new().unwrap(); 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::bussy::{channels, Command, Message, PubSub};
use crate::utils::error::Error; use crate::utils::error::Error;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct BanInfo { pub struct BanInfo {
@ -18,10 +18,7 @@ impl SledDb {
pub fn new() -> Self { pub fn new() -> Self {
let db = sled::open("/tmp/sled_db").unwrap(); let db = sled::open("/tmp/sled_db").unwrap();
let banned_pubkeys = db.open_tree("banned_pubkeys").unwrap(); let banned_pubkeys = db.open_tree("banned_pubkeys").unwrap();
Self { Self { db, banned_pubkeys }
db,
banned_pubkeys
}
} }
pub async fn start(&mut self, pubsub: Arc<PubSub>) -> Result<(), Error> { 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> { 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()) { if let Ok(Some(_)) = self
return Ok(true) .banned_pubkeys
.insert(ban_info.pubkey, ban_info.reason.as_bytes())
{
return Ok(true);
} }
Ok(false) 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) { if let Ok(Some(banned)) = self.banned_pubkeys.get(pubkey) {
return true return true;
} }
false false
} }
@ -98,7 +98,10 @@ impl SledDb {
} }
async fn get_bans(&self) -> Result<Vec<BanInfo>, Error> { async fn get_bans(&self) -> Result<Vec<BanInfo>, Error> {
let bans: Vec<BanInfo> = self.banned_pubkeys.iter().filter_map(|row| { let bans: Vec<BanInfo> = self
.banned_pubkeys
.iter()
.filter_map(|row| {
if let Ok((k, v)) = row { if let Ok((k, v)) = row {
let ban_info = BanInfo { let ban_info = BanInfo {
pubkey: String::from_utf8(k.to_vec()).unwrap(), pubkey: String::from_utf8(k.to_vec()).unwrap(),
@ -109,7 +112,8 @@ impl SledDb {
} else { } else {
None None
} }
}).collect(); })
.collect();
Ok(bans) Ok(bans)
} }
@ -119,7 +123,7 @@ impl SledDb {
if let Ok(Some(reason)) = self.banned_pubkeys.get(pubkey) { if let Ok(Some(reason)) = self.banned_pubkeys.get(pubkey) {
let ban_info = BanInfo { let ban_info = BanInfo {
pubkey: pubkey.to_owned(), 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)); return Ok(Some(ban_info));
@ -133,6 +137,4 @@ impl SledDb {
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {}
}

View file

@ -22,9 +22,7 @@ impl Config {
.unwrap() .unwrap()
.public_key(); .public_key();
let db_path = std::env::var("DATABASE_URL") let db_path = std::env::var("DATABASE_URL").map(PathBuf::from).unwrap();
.map(PathBuf::from)
.unwrap();
Self { Self {
admin_pubkey, admin_pubkey,

View file

@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json; use serde_json;
use std::error::Error as StdError;
use std::{ use std::{
convert::From, convert::From,
fmt::{self, Display}, fmt::{self, Display},
}; };
use std::error::Error as StdError;
use validator::ValidationErrors; use validator::ValidationErrors;
use warp::{http::StatusCode, reject::Reject}; use warp::{http::StatusCode, reject::Reject};

View file

@ -1,8 +1,8 @@
pub mod config;
pub mod crypto; pub mod crypto;
pub mod error; pub mod error;
pub mod filter; pub mod filter;
mod nostr_filter_helpers; mod nostr_filter_helpers;
pub mod config;
pub mod rejection_handler; pub mod rejection_handler;
pub mod response; pub mod response;
pub mod structs; pub mod structs;