mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
More Url validation
This commit is contained in:
parent
5255d33fdd
commit
3795034b1e
@ -155,7 +155,7 @@ impl DbRelay {
|
|||||||
|
|
||||||
// Get from 'e' and 'p' tags
|
// Get from 'e' and 'p' tags
|
||||||
let sql =
|
let sql =
|
||||||
"INSERT OR IGNORE INTO RELAY (url, rank) SELECT DISTINCT field1, 3 FROM event_tag where (label='e' OR label='p') and field1 like 'wss%'";
|
"INSERT OR IGNORE INTO RELAY (url, rank) SELECT DISTINCT field1, 3 FROM event_tag where (label='e' OR label='p') and field1 like 'ws%://%'";
|
||||||
|
|
||||||
spawn_blocking(move || {
|
spawn_blocking(move || {
|
||||||
let maybe_db = GLOBALS.db.blocking_lock();
|
let maybe_db = GLOBALS.db.blocking_lock();
|
||||||
|
@ -128,7 +128,9 @@ impl Globals {
|
|||||||
.entry(id)
|
.entry(id)
|
||||||
.and_modify(|urls| {
|
.and_modify(|urls| {
|
||||||
if let Some(ref u) = url {
|
if let Some(ref u) = url {
|
||||||
urls.push(u.to_owned());
|
if let Ok(valid) = Url::new_validated(u) {
|
||||||
|
urls.push(valid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] });
|
.or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] });
|
||||||
@ -223,6 +225,9 @@ pub async fn followed_pubkeys() -> Vec<PublicKeyHex> {
|
|||||||
pub async fn follow_key_and_relay(pubkey: String, relay: String) -> Result<DbPerson, String> {
|
pub async fn follow_key_and_relay(pubkey: String, relay: String) -> Result<DbPerson, String> {
|
||||||
let pubkeyhex = PublicKeyHex(pubkey.clone());
|
let pubkeyhex = PublicKeyHex(pubkey.clone());
|
||||||
|
|
||||||
|
// Validate the url
|
||||||
|
let _ = Url::new_validated(&relay).map_err(|e| format!("{}", e))?;
|
||||||
|
|
||||||
// Create or update them
|
// Create or update them
|
||||||
let person = match DbPerson::fetch_one(pubkeyhex.clone())
|
let person = match DbPerson::fetch_one(pubkeyhex.clone())
|
||||||
.await
|
.await
|
||||||
|
Loading…
Reference in New Issue
Block a user