Webfinger might work now

This commit is contained in:
mStar aka a person 2024-01-29 17:08:52 +00:00
parent 935fc33094
commit d1e93ad8f0

View file

@ -21,6 +21,7 @@ import (
"github.com/julienschmidt/httprouter"
"gitlab.com/mstarongitlab/goutils/other"
"gitlab.com/mstarongitlab/linstrom/server"
"gitlab.com/mstarongitlab/linstrom/storage"
"gitlab.com/mstarongitlab/linstrom/types"
)
@ -55,12 +56,26 @@ func WebfingerEndpoint(server *server.Server) func(http.ResponseWriter, *http.Re
return
}
person, err := server.Storage.GetPersonByName(acc.Name)
if err != nil {
if errors.Is(err, storage.ErrNotFound) {
http.Error(w, fmt.Sprintf("Account %s not found", acc), http.StatusNotFound)
return
} else {
http.Error(w, fmt.Sprintf("Internal error: %s, please report", err.Error()), http.StatusInternalServerError)
}
}
response := WebfingerResponse{
Links: []webfingerLink{
{
Rel: "me",
Type: "application/activity+json",
Target: *other.Must(url.Parse("https://example.com")), // TODO: Replace this with actual link generation
Rel: "me",
Type: "application/activity+json",
Target: *other.Must(url.Parse(fmt.Sprintf(
"https://%s/api/ap/user/%s",
server.Config.General.Domain,
person.Uid,
))),
},
},
}
@ -68,8 +83,7 @@ func WebfingerEndpoint(server *server.Server) func(http.ResponseWriter, *http.Re
}
}
// acct:bugle@bugle.lol
// turns "acct:bugle@bugle.lol" into { Name: bugle, Host: bugle.lol }
func getAccountFromWebfingerResource(r string) (*types.AccountHandle, error) {
acctCheck, acc, found := strings.Cut(r, ":")
if !found || acctCheck != "acct" {