From d1e93ad8f0ec9a41b1766cea8be34a54e154d263 Mon Sep 17 00:00:00 2001 From: mStar aka a person <12024604-mstarongitlab@users.noreply.gitlab.com> Date: Mon, 29 Jan 2024 17:08:52 +0000 Subject: [PATCH] Webfinger might work now --- endpoints/api/ap/webfinger.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/endpoints/api/ap/webfinger.go b/endpoints/api/ap/webfinger.go index 9c55734..99142a2 100644 --- a/endpoints/api/ap/webfinger.go +++ b/endpoints/api/ap/webfinger.go @@ -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" {