2020-11-17 16:10:14 +00:00
|
|
|
package main
|
|
|
|
|
2021-01-21 16:59:47 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-03-31 12:55:36 +00:00
|
|
|
"io"
|
2021-01-21 16:59:47 +00:00
|
|
|
"net/http"
|
2021-06-18 12:32:03 +00:00
|
|
|
|
2022-02-25 15:29:42 +00:00
|
|
|
"go.goblog.app/app/pkgs/bufferpool"
|
2021-06-28 20:17:18 +00:00
|
|
|
"go.goblog.app/app/pkgs/contenttype"
|
2020-11-17 16:10:14 +00:00
|
|
|
)
|
|
|
|
|
2021-06-06 12:39:42 +00:00
|
|
|
func (a *goBlog) serveNodeInfoDiscover(w http.ResponseWriter, r *http.Request) {
|
2022-02-25 15:29:42 +00:00
|
|
|
buf := bufferpool.Get()
|
|
|
|
defer bufferpool.Put(buf)
|
2022-03-16 07:28:03 +00:00
|
|
|
err := json.NewEncoder(buf).Encode(map[string]any{
|
|
|
|
"links": []map[string]any{
|
2021-01-21 16:59:47 +00:00
|
|
|
{
|
2021-06-10 20:09:50 +00:00
|
|
|
"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
|
|
|
},
|
|
|
|
},
|
2021-02-16 15:26:21 +00:00
|
|
|
})
|
2022-02-25 15:29:42 +00:00
|
|
|
if err != nil {
|
|
|
|
a.serveError(w, r, "", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Header().Set(contentType, contenttype.JSONUTF8)
|
2022-04-10 09:46:35 +00:00
|
|
|
mw := a.min.Get().Writer(contenttype.JSON, w)
|
2022-03-31 12:55:36 +00:00
|
|
|
_, _ = io.Copy(mw, buf)
|
2022-02-25 15:29:42 +00:00
|
|
|
_ = mw.Close()
|
2020-11-17 16:10:14 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 12:39:42 +00:00
|
|
|
func (a *goBlog) serveNodeInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
|
localPosts, _ := a.db.countPosts(&postsRequestConfig{
|
2022-09-23 09:05:07 +00:00
|
|
|
status: []postStatus{statusPublished},
|
|
|
|
visibility: []postVisibility{visibilityPublic},
|
2021-01-15 20:56:46 +00:00
|
|
|
})
|
2022-02-25 15:29:42 +00:00
|
|
|
buf := bufferpool.Get()
|
|
|
|
defer bufferpool.Put(buf)
|
2022-04-10 09:46:35 +00:00
|
|
|
if err := json.NewEncoder(buf).Encode(map[string]any{
|
2021-01-21 16:59:47 +00:00
|
|
|
"version": "2.1",
|
2022-03-16 07:28:03 +00:00
|
|
|
"software": map[string]any{
|
2021-01-21 16:59:47 +00:00
|
|
|
"name": "goblog",
|
2021-06-28 20:17:18 +00:00
|
|
|
"repository": "https://go.goblog.app/app",
|
2021-01-21 16:59:47 +00:00
|
|
|
},
|
2022-03-16 07:28:03 +00:00
|
|
|
"usage": map[string]any{
|
|
|
|
"users": map[string]any{
|
2021-06-06 12:39:42 +00:00
|
|
|
"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
|
|
|
},
|
2022-03-16 07:28:03 +00:00
|
|
|
"metadata": map[string]any{},
|
2022-04-10 09:46:35 +00:00
|
|
|
}); err != nil {
|
2022-02-25 15:29:42 +00:00
|
|
|
a.serveError(w, r, "", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Header().Set(contentType, contenttype.JSONUTF8)
|
2022-04-10 09:46:35 +00:00
|
|
|
_ = a.min.Get().Minify(contenttype.JSON, w, buf)
|
2020-11-17 16:10:14 +00:00
|
|
|
}
|