aboutsummaryrefslogtreecommitdiff
path: root/views/webfinger.go
blob: f500bc0d7311207403a8ccdfcdc399e3364fc55f (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
37
38
39
40
41
42
43
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.UrlActor(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",
			},
			{
				Rel:  "self",
				Href: actorUrl.String(),
				Type: "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
			},
		},
	}
	return &rs, nil
}