Add current nodeinfo 2.2 draft
This commit is contained in:
parent
f727b30f32
commit
e30cb6746a
3 changed files with 81 additions and 0 deletions
|
@ -120,6 +120,77 @@ func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
|
|||
_ = webutils.SendJson(w, data)
|
||||
}
|
||||
|
||||
func NodeInfo22(w http.ResponseWriter, r *http.Request) {
|
||||
u := dbgen.User
|
||||
log := hlog.FromRequest(r)
|
||||
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true), u.ServerId.Eq(1)).Count()
|
||||
if err != nil {
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
500,
|
||||
"/errors/db-failure",
|
||||
"internal database failure",
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get total user count from db")
|
||||
}
|
||||
return
|
||||
}
|
||||
n := dbgen.Note
|
||||
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
|
||||
if err != nil {
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
500,
|
||||
"/errors/db-failure",
|
||||
"internal database failure",
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get total note count from db")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data := webshared.NodeInfo2{
|
||||
Version: "2.2",
|
||||
Software: webshared.NodeInfo2Software{
|
||||
Name: "linstrom",
|
||||
Version: shared.Version,
|
||||
Homepage: other.IntoPointer("https://git.mstar.dev/mstar/linstrom"),
|
||||
Repository: other.IntoPointer("https://git.mstar.dev/mstar/linstrom"),
|
||||
},
|
||||
Instance: &webshared.NodeInfo2Instance{
|
||||
Name: config.GlobalConfig.Self.ServerDisplayName,
|
||||
Description: config.GlobalConfig.Self.ServerDescription,
|
||||
},
|
||||
Protocols: []string{"activitypub"},
|
||||
Services: map[string][]string{
|
||||
"inbound": {},
|
||||
"outbound": {},
|
||||
},
|
||||
OpenRegistrations: config.GlobalConfig.Admin.AllowRegistration,
|
||||
Usage: webshared.NodeInfo2Usage{
|
||||
Users: webshared.NodeInfo2UsageUsers{
|
||||
Total: uint(userCount),
|
||||
ActiveHalfYear: other.IntoPointer(uint(0)),
|
||||
ActiveMonth: other.IntoPointer(uint(0)),
|
||||
ActiveWeek: other.IntoPointer(uint(0)),
|
||||
},
|
||||
LocalPosts: uint(noteCount),
|
||||
LocalComments: 0},
|
||||
Metadata: map[string]any{},
|
||||
}
|
||||
_ = webutils.SendJson(w, data)
|
||||
}
|
||||
|
||||
func NodeInfo21(w http.ResponseWriter, r *http.Request) {
|
||||
u := dbgen.User
|
||||
log := hlog.FromRequest(r)
|
||||
|
|
|
@ -26,6 +26,7 @@ type NodeInfo2UsageUsers struct {
|
|||
Total uint `json:"total"`
|
||||
ActiveHalfYear *uint `json:"active_half_year"`
|
||||
ActiveMonth *uint `json:"active_month"`
|
||||
ActiveWeek *uint `json:"active_week,omitempty"`
|
||||
}
|
||||
|
||||
type NodeInfo2Usage struct {
|
||||
|
@ -34,8 +35,14 @@ type NodeInfo2Usage struct {
|
|||
LocalComments uint `json:"local_comments"`
|
||||
}
|
||||
|
||||
type NodeInfo2Instance struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type NodeInfo2 struct {
|
||||
Version string `json:"version"`
|
||||
Instance *NodeInfo2Instance `json:"instance,omitempty"`
|
||||
Software NodeInfo2Software `json:"software"`
|
||||
Protocols []string `json:"protocols"`
|
||||
Services map[string][]string `json:"services"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue