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::{
noose::user::{User, UserRow},
noose::sled::BanInfo,
noose::user::{User, UserRow},
utils::{error::Error, structs::Subscription},
};
use nostr::secp256k1::XOnlyPublicKey;

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,7 +98,10 @@ impl SledDb {
}
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 {
let ban_info = BanInfo {
pubkey: String::from_utf8(k.to_vec()).unwrap(),
@ -109,7 +112,8 @@ impl SledDb {
} else {
None
}
}).collect();
})
.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 {}

View file

@ -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,

View file

@ -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};

View file

@ -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;