mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Even more Url validation
This commit is contained in:
parent
ccf969f717
commit
26a6261312
@ -13,13 +13,15 @@ pub struct DbRelay {
|
||||
}
|
||||
|
||||
impl DbRelay {
|
||||
pub fn new(url: String) -> DbRelay {
|
||||
DbRelay {
|
||||
pub fn new(url: String) -> Result<DbRelay, Error> {
|
||||
let _ = Url::new_validated(&url)?;
|
||||
|
||||
Ok(DbRelay {
|
||||
url,
|
||||
success_count: 0,
|
||||
failure_count: 0,
|
||||
rank: Some(3),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn fetch(criteria: Option<&str>) -> Result<Vec<DbRelay>, Error> {
|
||||
@ -65,6 +67,8 @@ impl DbRelay {
|
||||
}
|
||||
|
||||
pub async fn insert(relay: DbRelay) -> Result<(), Error> {
|
||||
let _ = Url::new_validated(&relay.url)?;
|
||||
|
||||
let sql = "INSERT OR IGNORE INTO relay (url, success_count, failure_count, rank) \
|
||||
VALUES (?1, ?2, ?3, ?4)";
|
||||
|
||||
|
@ -333,7 +333,8 @@ pub async fn follow_key_and_relay(pubkey: String, relay: String) -> Result<DbPer
|
||||
};
|
||||
|
||||
// Insert (or ignore) this relay
|
||||
DbRelay::insert(DbRelay::new(relay.clone()))
|
||||
let dbrelay = DbRelay::new(relay.clone()).map_err(|e| format!("{}", e))?;
|
||||
DbRelay::insert(dbrelay)
|
||||
.await
|
||||
.map_err(|e| format!("{}", e))?;
|
||||
|
||||
|
@ -36,12 +36,14 @@ pub struct Minion {
|
||||
|
||||
impl Minion {
|
||||
pub async fn new(url: Url) -> Result<Minion, Error> {
|
||||
let _ = Url::new_validated(&url)?;
|
||||
|
||||
let to_overlord = GLOBALS.to_overlord.clone();
|
||||
let from_overlord = GLOBALS.to_minions.subscribe();
|
||||
let dbrelay = match DbRelay::fetch_one(&url).await? {
|
||||
Some(dbrelay) => dbrelay,
|
||||
None => {
|
||||
let dbrelay = DbRelay::new(url.0.clone());
|
||||
let dbrelay = DbRelay::new(url.0.clone())?;
|
||||
DbRelay::insert(dbrelay.clone()).await?;
|
||||
dbrelay
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ pub async fn process_new_event(
|
||||
} => {
|
||||
if let Ok(url) = Url::new_validated(should_be_url) {
|
||||
// Insert (or ignore) into relays table
|
||||
let dbrelay = DbRelay::new(url.0.clone());
|
||||
let dbrelay = DbRelay::new(url.0.clone())?;
|
||||
DbRelay::insert(dbrelay).await?;
|
||||
}
|
||||
}
|
||||
@ -93,7 +93,7 @@ pub async fn process_new_event(
|
||||
} => {
|
||||
if let Ok(url) = Url::new_validated(should_be_url) {
|
||||
// Insert (or ignore) into relays table
|
||||
let dbrelay = DbRelay::new(url.0.clone());
|
||||
let dbrelay = DbRelay::new(url.0.clone())?;
|
||||
DbRelay::insert(dbrelay).await?;
|
||||
|
||||
// upsert person_relay.last_suggested_bytag
|
||||
|
Loading…
Reference in New Issue
Block a user