mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-15 08:47:30 -06:00
tidy up some federation stuff
This commit is contained in:
parent
621e59fd42
commit
211c43073f
11 changed files with 199 additions and 86 deletions
|
|
@ -64,6 +64,10 @@ var (
|
|||
// inboxPathRegex parses a path that validates and captures the username part from eg /users/example_username/inbox
|
||||
inboxPathRegex = regexp.MustCompile(inboxPathRegexString)
|
||||
|
||||
outboxPathRegexString = fmt.Sprintf(`^/?%s/(%s)/%s$`, UsersPath, usernameRegexString, OutboxPath)
|
||||
// outboxPathRegex parses a path that validates and captures the username part from eg /users/example_username/outbox
|
||||
outboxPathRegex = regexp.MustCompile(outboxPathRegexString)
|
||||
|
||||
actorPathRegexString = fmt.Sprintf(`^?/%s/(%s)$`, ActorsPath, usernameRegexString)
|
||||
// actorPathRegex parses a path that validates and captures the username part from eg /actors/example_username
|
||||
actorPathRegex = regexp.MustCompile(actorPathRegexString)
|
||||
|
|
|
|||
|
|
@ -137,6 +137,11 @@ func IsInboxPath(id *url.URL) bool {
|
|||
return inboxPathRegex.MatchString(strings.ToLower(id.Path))
|
||||
}
|
||||
|
||||
// IsOutboxPath returns true if the given URL path corresponds to eg /users/example_username/outbox
|
||||
func IsOutboxPath(id *url.URL) bool {
|
||||
return outboxPathRegex.MatchString(strings.ToLower(id.Path))
|
||||
}
|
||||
|
||||
// IsInstanceActorPath returns true if the given URL path corresponds to eg /actors/example_username
|
||||
func IsInstanceActorPath(id *url.URL) bool {
|
||||
return actorPathRegex.MatchString(strings.ToLower(id.Path))
|
||||
|
|
@ -195,3 +200,14 @@ func ParseInboxPath(id *url.URL) (username string, err error) {
|
|||
username = matches[1]
|
||||
return
|
||||
}
|
||||
|
||||
// ParseOutboxPath returns the username from a path such as /users/example_username/outbox
|
||||
func ParseOutboxPath(id *url.URL) (username string, err error) {
|
||||
matches := outboxPathRegex.FindStringSubmatch(id.Path)
|
||||
if len(matches) != 2 {
|
||||
err = fmt.Errorf("expected 2 matches but matches length was %d", len(matches))
|
||||
return
|
||||
}
|
||||
username = matches[1]
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue