diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-24 20:23:39 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-24 20:30:55 +0100 |
| commit | 557d9295e3fc6145073459da94905765de53be1e (patch) | |
| tree | 6f0e49b4cd22e30f1d366060df3ee45f3c210efc | |
| parent | 0f34bbdb452f287a03167abe24011bc35cc85c26 (diff) | |
feat(init): make default ngit-relays configurable
make the default set of ngit-relays configurable
| -rw-r--r-- | src/bin/ngit/cli.rs | 7 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 12 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 5461237..ce4e12e 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs | |||
| @@ -40,10 +40,11 @@ pub const CUSTOMISE_TEMPLATE: &str = r" | |||
| 40 | ========================== | 40 | ========================== |
| 41 | ngit settings are managed through the git config. | 41 | ngit settings are managed through the git config. |
| 42 | 42 | ||
| 43 | Currently the only settings not not reachable through standard commands relate to default hardcoded relays: | 43 | Currently the only settings not reachable through standard commands relate to default hardcoded relays: |
| 44 | 44 | ||
| 45 | - nostr.relay-default-set - must have at least 1 value | 45 | - nostr.ngit-relay-default-set - only used during `ngit init` |
| 46 | - nostr.relay-blaster-set | 46 | - nostr.relay-default-set - must have at least 1 value, all events send to repo relays, user write and default relays |
| 47 | - nostr.relay-blaster-set - only used for repo announcement events | ||
| 47 | - nostr.relay-signer-fallback-set | 48 | - nostr.relay-signer-fallback-set |
| 48 | 49 | ||
| 49 | These take a string of semi-colon separated websocket URLs without spaces. For example: | 50 | These take a string of semi-colon separated websocket URLs without spaces. For example: |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index f348c0d..1d9fda0 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -252,6 +252,15 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 252 | args.blossoms.clone() | 252 | args.blossoms.clone() |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | let fallback_ngit_relays = | ||
| 256 | if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.ngit-relay-default-set", None) { | ||
| 257 | s.split(';') | ||
| 258 | .filter_map(|url| normalize_ngit_relay_url(url).ok()) // Attempt to parse and filter out errors | ||
| 259 | .collect() | ||
| 260 | } else { | ||
| 261 | vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] | ||
| 262 | }; | ||
| 263 | |||
| 255 | let selected_ngit_relays = if has_server_and_relay_flags { | 264 | let selected_ngit_relays = if has_server_and_relay_flags { |
| 256 | // ignore so a script running `ngit init` can contiue without prompts | 265 | // ignore so a script running `ngit init` can contiue without prompts |
| 257 | vec![] | 266 | vec![] |
| @@ -265,8 +274,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 265 | ); | 274 | ); |
| 266 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options | 275 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options |
| 267 | let empty = options.is_empty(); | 276 | let empty = options.is_empty(); |
| 268 | let fallbacks = vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()]; | 277 | for fallback in fallback_ngit_relays { |
| 269 | for fallback in fallbacks { | ||
| 270 | // Check if any option contains the fallback as a substring | 278 | // Check if any option contains the fallback as a substring |
| 271 | if !options.iter().any(|option| option.contains(&fallback)) { | 279 | if !options.iter().any(|option| option.contains(&fallback)) { |
| 272 | options.push(fallback.clone()); // Add fallback if not found | 280 | options.push(fallback.clone()); // Add fallback if not found |