mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 09:54:24 +01:00
Use and validate source in ActorID struct
This commit is contained in:
parent
546ce50337
commit
3a938b6c3f
|
@ -5,6 +5,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/forgefed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Validatable interface { // ToDo: What is the right package for this interface?
|
type Validatable interface { // ToDo: What is the right package for this interface?
|
||||||
|
@ -70,8 +72,13 @@ func (a ActorID) Validate() []string {
|
||||||
err = append(err, res.Error())
|
err = append(err, res.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(a.path, "api/v1/activitypub/user-id") { // This needs to happen in dependence to the star source type.
|
switch a.source {
|
||||||
err = append(err, fmt.Errorf("the Path to the API was invalid: %v", a.path).Error())
|
case "forgejo", "gitea":
|
||||||
|
if !strings.Contains(a.path, "api/v1/activitypub/user-id") {
|
||||||
|
err = append(err, fmt.Errorf("the Path to the API was invalid: %v", a.path).Error())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
err = append(err, fmt.Errorf("currently only forgeo and gitea sources are allowed from actor id").Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -104,8 +111,9 @@ func ParseActorID(actor string) (ActorID, error) {
|
||||||
userId := pathWithUserID[len(pathWithUserID)-1]
|
userId := pathWithUserID[len(pathWithUserID)-1]
|
||||||
|
|
||||||
return ActorID{ // ToDo: maybe keep original input to validate against (maybe extra method)
|
return ActorID{ // ToDo: maybe keep original input to validate against (maybe extra method)
|
||||||
schema: u.Scheme, // ToDo: Add source type field
|
|
||||||
userId: userId,
|
userId: userId,
|
||||||
|
source: star.Source,
|
||||||
|
schema: u.Scheme, // ToDo: Add source type field
|
||||||
host: u.Host,
|
host: u.Host,
|
||||||
path: u.Path,
|
path: u.Path,
|
||||||
port: u.Port(),
|
port: u.Port(),
|
||||||
|
|
Loading…
Reference in a new issue