diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/repo_ref.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 5e857e9..b2bd381 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -326,12 +326,7 @@ impl RepoRef { | |||
| 326 | 326 | ||
| 327 | // returns false if already present so didn't need adding | 327 | // returns false if already present so didn't need adding |
| 328 | pub fn add_grasp_server(&mut self, clone_url: &str) -> Result<bool> { | 328 | pub fn add_grasp_server(&mut self, clone_url: &str) -> Result<bool> { |
| 329 | if !clone_url.starts_with("http") { | 329 | if !is_grasp_server_clone_url(clone_url) { |
| 330 | bail!("invalid grasp server clone url"); | ||
| 331 | } | ||
| 332 | extract_npub(clone_url) | ||
| 333 | .context("invalid grasp server clone url. does not contain valid npub")?; | ||
| 334 | if !(clone_url.ends_with(".git") || clone_url.ends_with(".git/")) { | ||
| 335 | bail!("invalid grasp server clone url. does not end with .git"); | 330 | bail!("invalid grasp server clone url. does not end with .git"); |
| 336 | } | 331 | } |
| 337 | 332 | ||
| @@ -739,7 +734,6 @@ pub fn extract_npub(s: &str) -> Result<&str> { | |||
| 739 | } | 734 | } |
| 740 | } | 735 | } |
| 741 | 736 | ||
| 742 | // this should be called is_grasp_server_in_list | ||
| 743 | pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool { | 737 | pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool { |
| 744 | if !grasp_servers.is_empty() { | 738 | if !grasp_servers.is_empty() { |
| 745 | if let Ok(url) = normalize_grasp_server_url(url) { | 739 | if let Ok(url) = normalize_grasp_server_url(url) { |
| @@ -758,6 +752,12 @@ pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool { | |||
| 758 | } | 752 | } |
| 759 | } | 753 | } |
| 760 | 754 | ||
| 755 | pub fn is_grasp_server_clone_url(url: &str) -> bool { | ||
| 756 | extract_npub(url).is_ok() | ||
| 757 | && (url.ends_with(".git") || url.ends_with(".git/")) | ||
| 758 | && url.starts_with("http") | ||
| 759 | } | ||
| 760 | |||
| 761 | pub fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> { | 761 | pub fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> { |
| 762 | let grasp_server_url = normalize_grasp_server_url(url)?; | 762 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 763 | if grasp_server_url.contains("http://") { | 763 | if grasp_server_url.contains("http://") { |