/
nodeinfo.go
97 lines (89 loc) · 2.46 KB
/
nodeinfo.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
package wellknown
import (
"errors"
"fmt"
"net/http"
"github.com/davecheney/pub/activitypub"
"github.com/davecheney/pub/internal/httpx"
"github.com/davecheney/pub/internal/to"
"github.com/davecheney/pub/models"
"github.com/go-chi/chi/v5"
"gorm.io/gorm"
)
func NodeInfoIndex(env *activitypub.Env, w http.ResponseWriter, r *http.Request) error {
w.Header().Set("cache-control", "max-age=259200, public")
return to.JSON(w, map[string]any{
"links": []any{
map[string]any{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": fmt.Sprintf("https://%s/nodeinfo/2.0", r.Host),
},
map[string]any{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
"href": fmt.Sprintf("https://%s/nodeinfo/2.1", r.Host),
},
},
})
}
func NodeInfoShow(env *activitypub.Env, w http.ResponseWriter, r *http.Request) error {
var instance models.Instance
if err := env.DB.Where("domain = ?", r.Host).First(&instance).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return httpx.Error(http.StatusNotFound, err)
}
return err
}
switch chi.URLParam(r, "version") {
case "2.0":
// https://github.com/jhass/nodeinfo/blob/main/schemas/2.0/schema.json
w.Header().Set("cache-control", "max-age=259200, public")
return to.JSON(w, map[string]any{
"version": "2.0",
"software": map[string]any{
"name": "https://github.com/davecheney/pub",
"version": "0.0.0-devel",
},
"protocols": protocols(),
"services": services(),
"usage": usage(),
"openRegistrations": false,
"metadata": metadata(),
})
case "2.1":
w.Header().Set("cache-control", "max-age=259200, public")
return to.JSON(w, map[string]any{
"version": "2.1",
"software": map[string]any{
"name": "pub",
"version": "0.0.0-devel",
"repository": "https://github.com/davecheney/pub",
},
"protocols": protocols(),
"services": services(),
"usage": usage(),
"openRegistrations": false,
"metadata": metadata(),
})
default:
return httpx.Error(http.StatusNotFound, errors.New("unsupported version: "+chi.URLParam(r, "version")))
}
}
func metadata() map[string]any {
return map[string]any{}
}
func protocols() []any {
return []any{
"activitypub",
}
}
func services() map[string]any {
return map[string]any{
"inbound": []any{},
"outbound": []any{},
}
}
func usage() map[string]any {
return map[string]any{
"users": map[string]any{},
}
}