mirror of
https://github.com/fiatjaf/nak.git
synced 2026-06-04 17:51:15 +02:00
git: support nostr://... URLs without requiring the <relay> component.
This commit is contained in:
50
git.go
50
git.go
@@ -369,7 +369,7 @@ aside from those, there is also:
|
||||
{
|
||||
Name: "clone",
|
||||
Usage: "clone a NIP-34 repository from a nostr:// URI",
|
||||
Description: `the <repository> parameter maybe in the form "<npub, hex, nprofile or nip05>/<identifier>", ngit-style like "nostr://<npub>/<relay>/<identifier>" or an "naddr1..." code.`,
|
||||
Description: `the <repository> parameter maybe in the form "<npub, hex, nprofile or nip05>/<identifier>", ngit-style like "nostr://<npub>/<relay>/<identifier>" or "nostr://<npub>/<identifier>" or an "naddr1..." code.`,
|
||||
ArgsUsage: "<repository> [directory]",
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
args := c.Args()
|
||||
@@ -2633,30 +2633,40 @@ func parseRepositoryAddress(
|
||||
}
|
||||
|
||||
// format 2: nostr://<npub_or_nip05>/<relay_hostname>/<identifier> (ngit-style)
|
||||
// format 2b: nostr://<npub_or_nip05>/<identifier> (without relay)
|
||||
if strings.HasPrefix(address, "nostr://") {
|
||||
parts := strings.Split(address, "/")
|
||||
if len(parts) != 5 {
|
||||
if len(parts) == 5 {
|
||||
// nostr://<owner>/<relay>/<identifier>
|
||||
owner, err = parsePubKey(parts[2])
|
||||
if err != nil {
|
||||
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
|
||||
}
|
||||
|
||||
relayHost := parts[3]
|
||||
identifier = parts[4]
|
||||
|
||||
if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") {
|
||||
relayHints = []string{relayHost}
|
||||
} else {
|
||||
relayHints = []string{"wss://" + relayHost}
|
||||
}
|
||||
|
||||
return owner, identifier, relayHints, nil
|
||||
} else if len(parts) == 4 {
|
||||
// nostr://<owner>/<identifier>
|
||||
owner, err = parsePubKey(parts[2])
|
||||
if err != nil {
|
||||
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
|
||||
}
|
||||
|
||||
identifier = parts[3]
|
||||
return owner, identifier, nil, nil
|
||||
} else {
|
||||
return nostr.PubKey{}, "", nil, fmt.Errorf(
|
||||
"invalid nostr URL format, expected nostr://<npub|nip05>/<relay_hostname>/<identifier>, got: %s", address,
|
||||
"invalid nostr URL format, expected nostr://<npub|nip05>/<identifier> or nostr://<npub|nip05>/<relay>/<identifier>, got: %s", address,
|
||||
)
|
||||
}
|
||||
|
||||
owner, err = parsePubKey(parts[2])
|
||||
if err != nil {
|
||||
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
|
||||
}
|
||||
|
||||
relayHost := parts[3]
|
||||
identifier = parts[4]
|
||||
|
||||
// construct relay hint from hostname
|
||||
if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") {
|
||||
relayHints = []string{relayHost}
|
||||
} else {
|
||||
relayHints = []string{"wss://" + relayHost}
|
||||
}
|
||||
|
||||
return owner, identifier, relayHints, nil
|
||||
}
|
||||
|
||||
// format 3: <npub, hex, nprofile or nip05>/<identifier>
|
||||
|
||||
Reference in New Issue
Block a user