aboutsummaryrefslogtreecommitdiff
path: root/views/webfinger.go
blob: 5af63088dcbfa35c5eb2228fb583fbd207f4e318 (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{},
		Links: []Link{{
			Rel:  "self",
			Href: actorUrl.String(),
			Type: "application/activity+json",
		}},
	}
	return &rs, nil
}