forked from davecheney/pub
/
users.go
113 lines (110 loc) · 3.62 KB
/
users.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package activitypub
import (
"net/http"
"github.com/bardic/pub/internal/httpx"
"github.com/bardic/pub/internal/to"
"github.com/bardic/pub/models"
"github.com/go-chi/chi/v5"
"gorm.io/gorm"
)
func UsersShow(env *Env, w http.ResponseWriter, r *http.Request) error {
var actor models.Actor
if err := env.DB.First(&actor, "name = ? and domain = ?", chi.URLParam(r, "name"), r.Host).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return httpx.Error(http.StatusNotFound, err)
}
return err
}
return to.JSON(w, map[string]any{
"@context": []any{
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
map[string]any{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"toot": "http://joinmastodon.org/ns#",
"featured": map[string]any{
"@id": "toot:featured",
"@type": "@id",
},
"featuredTags": map[string]any{
"@id": "toot:featuredTags",
"@type": "@id",
},
"alsoKnownAs": map[string]any{
"@id": "as:alsoKnownAs",
"@type": "@id",
},
"movedTo": map[string]any{
"@id": "as:movedTo",
"@type": "@id",
},
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"discoverable": "toot:discoverable",
"Device": "toot:Device",
"Ed25519Signature": "toot:Ed25519Signature",
"Ed25519Key": "toot:Ed25519Key",
"Curve25519Key": "toot:Curve25519Key",
"EncryptedMessage": "toot:EncryptedMessage",
"publicKeyBase64": "toot:publicKeyBase64",
"deviceId": "toot:deviceId",
"claim": map[string]any{
"@type": "@id",
"@id": "toot:claim",
},
"fingerprintKey": map[string]any{
"@type": "@id",
"@id": "toot:fingerprintKey",
},
"identityKey": map[string]any{
"@type": "@id",
"@id": "toot:identityKey",
},
"devices": map[string]any{
"@type": "@id",
"@id": "toot:devices",
},
"messageFranking": "toot:messageFranking",
"messageType": "toot:messageType",
"cipherText": "toot:cipherText",
"suspended": "toot:suspended",
"focalPoint": map[string]any{
"@container": "@list",
"@id": "toot:focalPoint",
},
},
},
"id": actor.URI,
"type": actor.ActorType(),
"following": actor.URI + "/following",
"followers": actor.URI + "/followers",
"inbox": actor.URI + "/inbox",
"outbox": actor.URI + "/outbox",
"featured": actor.URI + "/collections/featured",
"featuredTags": actor.URI + "/collections/tags",
"preferredUsername": actor.Name,
"name": actor.DisplayName,
"summary": actor.Note,
"url": actor.URL(),
"manuallyApprovesFollowers": actor.Locked,
"discoverable": false, // mastodon sets this to false
"published": actor.ID.ToTime().Format("2006-01-02T00:00:00Z"), // spec says round created_at to nearest day
"devices": actor.URI + "/collections/devices",
"publicKey": map[string]any{
"id": actor.PublicKeyID(),
"owner": actor.URI,
"publicKeyPem": string(actor.PublicKey),
},
"tag": []any{},
"attachment": []any{},
"endpoints": map[string]any{
"sharedInbox": "https://" + r.Host + "/inbox",
},
"icon": map[string]any{
"type": "Image",
"mediaType": "image/jpeg",
"url": actor.Avatar,
},
})
}