Command 'delete_relay' to get rid of mistaken (but technically valid) URLs like "wss://pleb.cloud,wss//nostr.mom"

This commit is contained in:
Mike Dilger 2023-12-22 13:10:36 +13:00
parent 42ebc6a25d
commit ad6f406cd3

View File

@ -28,7 +28,7 @@ impl Command {
}
}
const COMMANDS: [Command; 26] = [
const COMMANDS: [Command; 27] = [
Command {
cmd: "oneshot",
usage_params: "{depends}",
@ -59,6 +59,11 @@ const COMMANDS: [Command; 26] = [
usage_params: "<pubkeyhex> <ciphertext>",
desc: "decrypt the ciphertext from the pubkeyhex.",
},
Command {
cmd: "delete_relay",
usage_params: "<relayurl>",
desc: "delete a relay record from storage.",
},
Command {
cmd: "events_of_kind",
usage_params: "<kind>",
@ -184,6 +189,7 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
"bech32_decode" => bech32_decode(command, args)?,
"bech32_encode_event_addr" => bech32_encode_event_addr(command, args)?,
"decrypt" => decrypt(command, args)?,
"delete_relay" => delete_relay(command, args)?,
"events_of_kind" => events_of_kind(command, args)?,
"events_of_pubkey_and_kind" => events_of_pubkey_and_kind(command, args)?,
"giftwrap_ids" => giftwrap_ids(command)?,
@ -412,6 +418,17 @@ pub fn decrypt(cmd: Command, mut args: env::Args) -> Result<(), Error> {
Ok(())
}
pub fn delete_relay(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let rurl = match args.next() {
Some(urlstr) => RelayUrl::try_from_str(&urlstr)?,
None => return cmd.usage("Missing relay url parameter".to_string()),
};
GLOBALS.storage.delete_relay(&rurl, None)?;
Ok(())
}
pub fn import_event(cmd: Command, mut args: env::Args, runtime: &Runtime) -> Result<(), Error> {
let event = match args.next() {
Some(json) => {