From 6d3a4eb870cd344b11ccda13e1339584ed4e4d17 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 9 Dec 2024 09:34:08 +0000 Subject: feat(NostrUrlDecoded) add nip05 support replace `NostrUrlDecoded::from_str` with `NostrUrlDecoded::parse_and_resolve` store nip05 pubkey mapping in git cache --- src/bin/git_remote_nostr/main.rs | 12 ++++++------ src/bin/ngit/sub_commands/init.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/bin') diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 8e12d68..84327d7 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -9,7 +9,6 @@ use std::{ collections::HashSet, env, io, path::{Path, PathBuf}, - str::FromStr, }; use anyhow::{bail, Context, Result}; @@ -28,7 +27,7 @@ mod utils; #[tokio::main] async fn main() -> Result<()> { - let Some((decoded_nostr_url, git_repo)) = process_args()? else { + let Some((decoded_nostr_url, git_repo)) = process_args().await? else { return Ok(()); }; @@ -109,7 +108,7 @@ async fn main() -> Result<()> { } } -fn process_args() -> Result> { +async fn process_args() -> Result> { let args = env::args(); let args = args.skip(1).take(2).collect::>(); @@ -135,13 +134,14 @@ fn process_args() -> Result> { return Ok(None); }; - let decoded_nostr_url = - NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?; - let git_repo = Repo::from_path(&PathBuf::from( std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?, ))?; + let decoded_nostr_url = NostrUrlDecoded::parse_and_resolve(nostr_remote_url, &Some(&git_repo)) + .await + .context("invalid nostr url")?; + Ok(Some((decoded_nostr_url, git_repo))) } diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 6fc1ec4..c9c8873 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, str::FromStr}; +use std::collections::HashMap; use anyhow::{Context, Result}; use console::Style; @@ -442,7 +442,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .map(std::string::ToString::to_string) .collect::>(); - prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo)?; + prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo).await?; // TODO: if no state event exists and there is currently a remote called // "origin", automtically push rather than waiting for the next commit @@ -483,7 +483,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { Ok(()) } -fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> { +async fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> { println!( "starting from your next commit, when you `git push` to a remote that uses your nostr url, it will store your repository state on nostr and update the state of the git server(s) you just listed." ); @@ -493,7 +493,9 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { if let Some(origin_url) = origin_remote.url() { - if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { + if let Ok(nostr_url) = + NostrUrlDecoded::parse_and_resolve(origin_url, &Some(git_repo)).await + { if nostr_url.coordinate.identifier == repo_ref.identifier { if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer { return Ok(()); -- cgit v1.2.3