Format files
This commit is contained in:
parent
ecb49bf88a
commit
ab9fe76494
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,18 +98,22 @@ 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
|
||||||
if let Ok((k, v)) = row {
|
.banned_pubkeys
|
||||||
let ban_info = BanInfo {
|
.iter()
|
||||||
pubkey: String::from_utf8(k.to_vec()).unwrap(),
|
.filter_map(|row| {
|
||||||
reason: String::from_utf8(v.to_vec()).unwrap(),
|
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)
|
Some(ban_info)
|
||||||
} 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 {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ async fn handle_req(
|
||||||
client: &mut Client,
|
client: &mut Client,
|
||||||
subscription_id: SubscriptionId,
|
subscription_id: SubscriptionId,
|
||||||
filters: Vec<Filter>,
|
filters: Vec<Filter>,
|
||||||
) {
|
) {
|
||||||
let subscription = Subscription::new(subscription_id.clone(), filters);
|
let subscription = Subscription::new(subscription_id.clone(), filters);
|
||||||
let needs_historical_events = subscription.needs_historical_events();
|
let needs_historical_events = subscription.needs_historical_events();
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ async fn handle_req(
|
||||||
client.ip(),
|
client.ip(),
|
||||||
&subscription_error.message
|
&subscription_error.message
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = format!(
|
let message = format!(
|
||||||
"[\"CLOSED\", \"{}\", \"{}\"]",
|
"[\"CLOSED\", \"{}\", \"{}\"]",
|
||||||
subscription_id, subscription_error.message
|
subscription_id, subscription_error.message
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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};
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -125,7 +125,7 @@ fn tag_match(filter: &Filter, event: &Event) -> bool {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
filter
|
filter
|
||||||
.generic_tags
|
.generic_tags
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in a new issue