/
actor.go
86 lines (78 loc) · 1.97 KB
/
actor.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package web
import (
"fmt"
"github.com/deemkeen/stegodon/db"
"github.com/deemkeen/stegodon/util"
"strings"
)
type action uint
const (
id action = iota
inbox
outbox
followers
following
sharedInbox
)
func GetActor(actor string, conf *util.AppConfig) (error, string) {
err, acc := db.GetDB().ReadAccByUsername(actor)
if err != nil {
return err, "{}"
}
username := acc.Username
pubKey := strings.Replace(acc.WebPublicKey, "\n", "\\n", -1)
return nil, fmt.Sprintf(
`{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "%s",
"type": "Person",
"preferredUsername": "%s",
"name" : "%s",
"inbox": "%s",
"outbox": "%s",
"followers": "%s",
"following": "%s",
"url": "%s",
"manuallyApprovesFollowers": false,
"discoverable": true,
"endpoints": {
"sharedInbox": "%s"
},
"publicKey": {
"id": "%s#main-key",
"owner": "%s",
"publicKeyPem": "%s"
}
}`,
getIRI(conf.Conf.SslDomain, username, id),
username, username, getIRI(conf.Conf.SslDomain, username, inbox),
getIRI(conf.Conf.SslDomain, username, outbox),
getIRI(conf.Conf.SslDomain, username, followers),
getIRI(conf.Conf.SslDomain, username, following),
getIRI(conf.Conf.SslDomain, username, id),
getIRI(conf.Conf.SslDomain, username, sharedInbox),
getIRI(conf.Conf.SslDomain, username, id),
getIRI(conf.Conf.SslDomain, username, id), pubKey)
}
func getIRI(domain string, username string, action action) string {
prefix := fmt.Sprintf("https://%s/users/%s", domain, username)
switch action {
case inbox:
return fmt.Sprintf("/%s/inbox", prefix)
case outbox:
return fmt.Sprintf("/%s/outbox", prefix)
case followers:
return fmt.Sprintf("%s/followers", prefix)
case following:
return fmt.Sprintf("%s/following", prefix)
case id:
return prefix
case sharedInbox:
return fmt.Sprintf("https://%s/inbox", domain)
default:
return ""
}
}