diff options
Diffstat (limited to 'internal/message')
-rw-r--r-- | internal/message/fediprocess.go | 30 | ||||
-rw-r--r-- | internal/message/instanceprocess.go | 2 | ||||
-rw-r--r-- | internal/message/processor.go | 3 |
3 files changed, 34 insertions, 1 deletions
diff --git a/internal/message/fediprocess.go b/internal/message/fediprocess.go index 6dc6330cf..dad1e848c 100644 --- a/internal/message/fediprocess.go +++ b/internal/message/fediprocess.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/go-fed/activity/streams" + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) @@ -100,3 +101,32 @@ func (p *processor) GetFediUser(requestedUsername string, request *http.Request) return data, nil } + +func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) { + // get the account the request is referring to + requestedAccount := >smodel.Account{} + if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil { + return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err)) + } + + // return the webfinger representation + return &apimodel.WebfingerAccountResponse{ + Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.Host), + Aliases: []string{ + requestedAccount.URI, + requestedAccount.URL, + }, + Links: []apimodel.WebfingerLink{ + { + Rel: "http://webfinger.net/rel/profile-page", + Type: "text/html", + Href: requestedAccount.URL, + }, + { + Rel: "self", + Type: "application/activity+json", + Href: requestedAccount.URI, + }, + }, + }, nil +} diff --git a/internal/message/instanceprocess.go b/internal/message/instanceprocess.go index 16a5594de..0b0f15501 100644 --- a/internal/message/instanceprocess.go +++ b/internal/message/instanceprocess.go @@ -18,5 +18,5 @@ func (p *processor) InstanceGet(domain string) (*apimodel.Instance, ErrorWithCod return nil, NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err)) } - return ai, nil + return ai, nil } diff --git a/internal/message/processor.go b/internal/message/processor.go index 0c0334e20..d150d56e6 100644 --- a/internal/message/processor.go +++ b/internal/message/processor.go @@ -108,6 +108,9 @@ type Processor interface { // GetFediUser handles the getting of a fedi/activitypub representation of a user/account, performing appropriate authentication // before returning a JSON serializable interface to the caller. GetFediUser(requestedUsername string, request *http.Request) (interface{}, ErrorWithCode) + + // GetWebfingerAccount handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups. + GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) } // processor just implements the Processor interface |