aboutsummaryrefslogtreecommitdiff
path: root/views/webfinger.go
blob: e6ddc2398a27455fc0cf06ce8d9621724fbb31fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package views

import (
	"fmt"

	"git.capotej.com/capotej/communique/urls"
)

type Link struct {
	Rel  string `json:"rel"`
	Type string `json:"type"`
	Href string `json:"href"`
}

type WebfingerResource struct {
	Subject string   `json:"subject"`
	Aliases []string `json:"aliases"`
	Links   []Link   `json:"links"`
}

func RenderWebfinger(name, domain, hostname string) (*WebfingerResource, error) {
	actorUrl, err := urls.UrlProfile(name, domain)
	if err != nil {
		return nil, err
	}
	rs := WebfingerResource{
		Subject: fmt.Sprintf("acct:%s%s", name, hostname), //hostname contains @
		Aliases: []string{actorUrl.String()},
		Links: []Link{{
			Rel:  "self",
			Href: actorUrl.String(),
			Type: "application/activity+json",
		}},
	}
	return &rs, nil
}