Add current nodeinfo 2.2 draft

This commit is contained in:
Melody Becker 2025-06-11 09:14:49 +02:00
parent f727b30f32
commit e30cb6746a
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
3 changed files with 81 additions and 0 deletions

View file

@ -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)