GoBlog/nodeinfo.go

49 lines
1.2 KiB
Go
Raw Normal View History

2020-11-17 16:10:14 +00:00
package main
2021-01-21 16:59:47 +00:00
import (
"encoding/json"
"net/http"
"git.jlel.se/jlelse/GoBlog/pkgs/contenttype"
2020-11-17 16:10:14 +00:00
)
func (a *goBlog) serveNodeInfoDiscover(w http.ResponseWriter, r *http.Request) {
b, _ := json.Marshal(map[string]interface{}{
2021-01-21 16:59:47 +00:00
"links": []map[string]interface{}{
{
"href": a.getFullAddress("/nodeinfo"),
2021-01-21 16:59:47 +00:00
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
2020-11-17 16:10:14 +00:00
},
},
})
w.Header().Set(contentType, contenttype.JSONUTF8)
_, _ = a.min.Write(w, contenttype.JSON, b)
2020-11-17 16:10:14 +00:00
}
func (a *goBlog) serveNodeInfo(w http.ResponseWriter, r *http.Request) {
localPosts, _ := a.db.countPosts(&postsRequestConfig{
2021-01-15 20:56:46 +00:00
status: statusPublished,
})
b, _ := json.Marshal(map[string]interface{}{
2021-01-21 16:59:47 +00:00
"version": "2.1",
"software": map[string]interface{}{
"name": "goblog",
"repository": "https://git.jlel.se/jlelse/GoBlog",
},
"usage": map[string]interface{}{
"users": map[string]interface{}{
"total": len(a.cfg.Blogs),
2021-01-21 16:59:47 +00:00
},
"localPosts": localPosts,
},
"protocols": []string{
"activitypub",
"micropub",
"webmention",
2020-11-17 16:10:14 +00:00
},
2021-01-21 16:59:47 +00:00
"metadata": map[string]interface{}{},
})
w.Header().Set(contentType, contenttype.JSONUTF8)
_, _ = a.min.Write(w, contenttype.JSON, b)
2020-11-17 16:10:14 +00:00
}