upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/git/nostr_url.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/git/nostr_url.rs')
-rw-r--r--src/lib/git/nostr_url.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs
index 6b38a93..de7953f 100644
--- a/src/lib/git/nostr_url.rs
+++ b/src/lib/git/nostr_url.rs
@@ -55,7 +55,7 @@ impl FromStr for ServerProtocol {
55 } 55 }
56} 56}
57 57
58#[derive(Debug, PartialEq)] 58#[derive(Debug, PartialEq, Clone)]
59pub struct NostrUrlDecoded { 59pub struct NostrUrlDecoded {
60 pub original_string: String, 60 pub original_string: String,
61 pub coordinate: Coordinate, 61 pub coordinate: Coordinate,
@@ -73,7 +73,11 @@ impl fmt::Display for NostrUrlDecoded {
73 if let Some(protocol) = &self.protocol { 73 if let Some(protocol) = &self.protocol {
74 write!(f, "{}/", protocol)?; 74 write!(f, "{}/", protocol)?;
75 } 75 }
76 write!(f, "{}/", self.coordinate.public_key.to_bech32().unwrap())?; 76 if let Some(nip05) = &self.nip05 {
77 write!(f, "{}/", nip05)?;
78 } else {
79 write!(f, "{}/", self.coordinate.public_key.to_bech32().unwrap())?;
80 }
77 if let Some(relay) = self.coordinate.relays.first() { 81 if let Some(relay) = self.coordinate.relays.first() {
78 write!( 82 write!(
79 f, 83 f,
@@ -97,6 +101,7 @@ impl NostrUrlDecoded {
97 let mut protocol = None; 101 let mut protocol = None;
98 let mut user = None; 102 let mut user = None;
99 let mut relays = vec![]; 103 let mut relays = vec![];
104 let mut nip05 = None;
100 105
101 if !url.starts_with("nostr://") { 106 if !url.starts_with("nostr://") {
102 bail!("nostr git url must start with nostr://"); 107 bail!("nostr git url must start with nostr://");
@@ -157,7 +162,6 @@ impl NostrUrlDecoded {
157 } 162 }
158 // extract naddr npub/<optional-relays>/identifer 163 // extract naddr npub/<optional-relays>/identifer
159 let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?; 164 let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?;
160 let mut nip05 = None;
161 // naddr used 165 // naddr used
162 let coordinate = if let Ok(coordinate) = Coordinate::parse(part) { 166 let coordinate = if let Ok(coordinate) = Coordinate::parse(part) {
163 if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) { 167 if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) {
@@ -254,7 +258,7 @@ pub fn use_nip05_git_config_cache_to_find_nip05_from_public_key(
254 .cloned()) 258 .cloned())
255} 259}
256 260
257fn save_nip05_to_git_config_cache( 261pub fn save_nip05_to_git_config_cache(
258 nip05: &str, 262 nip05: &str,
259 public_key: &PublicKey, 263 public_key: &PublicKey,
260 git_repo: &Option<&Repo>, 264 git_repo: &Option<&Repo>,