1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Make the source an argument to the parser

This commit is contained in:
erik 2023-12-06 15:15:39 +01:00 committed by Michael Jerger
parent 2fb893843b
commit 4f25e5057a

View file

@ -6,7 +6,6 @@ import (
"strconv"
"strings"
"code.gitea.io/gitea/modules/forgefed"
"code.gitea.io/gitea/modules/log"
)
@ -20,7 +19,7 @@ type Validatable interface { // ToDo: What is the right package for this interfa
type ActorID struct {
userId string
source forgefed.SourceType
source string
schema string
path string
host string
@ -126,8 +125,8 @@ func removeEmptyStrings(ls []string) []string {
return rs
}
func ParseActorIDFromStarActivity(star *forgefed.Star) (ActorID, error) {
u, err := url.Parse(star.Actor.GetID().String())
func ParseActorID(unvalidatedIRI, source string) (ActorID, error) {
u, err := url.Parse(unvalidatedIRI)
// check if userID IRI is well formed url
if err != nil {
@ -150,7 +149,7 @@ func ParseActorIDFromStarActivity(star *forgefed.Star) (ActorID, error) {
return ActorID{ // ToDo: maybe keep original input to validate against (maybe extra method)
userId: userId,
source: star.Source,
source: source,
schema: u.Scheme,
host: u.Hostname(), // u.Host returns hostname:port
path: pathWithoutUserID,