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

@ -107,6 +107,8 @@ type ConfigSelf struct {
ServerActorDisplayName string `toml:"server_actor_display_name"` ServerActorDisplayName string `toml:"server_actor_display_name"`
// The name of the server provided via nodeinfo // The name of the server provided via nodeinfo
ServerDisplayName string `toml:"server_display_name"` ServerDisplayName string `toml:"server_display_name"`
// The description of the server
ServerDescription string `toml:"server_description"`
} }
// Contains experimental features that could be good to have // Contains experimental features that could be good to have
@ -212,6 +214,7 @@ var defaultConfig Config = Config{
Self: ConfigSelf{ Self: ConfigSelf{
ServerActorDisplayName: "Server actor", ServerActorDisplayName: "Server actor",
ServerDisplayName: "Linstrom", ServerDisplayName: "Linstrom",
ServerDescription: "A social media server running Linstrom",
}, },
S3: ConfigS3{ S3: ConfigS3{
KeyId: "Example key ID", KeyId: "Example key ID",

View file

@ -120,6 +120,77 @@ func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
_ = webutils.SendJson(w, data) _ = 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) { func NodeInfo21(w http.ResponseWriter, r *http.Request) {
u := dbgen.User u := dbgen.User
log := hlog.FromRequest(r) log := hlog.FromRequest(r)

View file

@ -26,6 +26,7 @@ type NodeInfo2UsageUsers struct {
Total uint `json:"total"` Total uint `json:"total"`
ActiveHalfYear *uint `json:"active_half_year"` ActiveHalfYear *uint `json:"active_half_year"`
ActiveMonth *uint `json:"active_month"` ActiveMonth *uint `json:"active_month"`
ActiveWeek *uint `json:"active_week,omitempty"`
} }
type NodeInfo2Usage struct { type NodeInfo2Usage struct {
@ -34,8 +35,14 @@ type NodeInfo2Usage struct {
LocalComments uint `json:"local_comments"` LocalComments uint `json:"local_comments"`
} }
type NodeInfo2Instance struct {
Name string `json:"name"`
Description string `json:"description"`
}
type NodeInfo2 struct { type NodeInfo2 struct {
Version string `json:"version"` Version string `json:"version"`
Instance *NodeInfo2Instance `json:"instance,omitempty"`
Software NodeInfo2Software `json:"software"` Software NodeInfo2Software `json:"software"`
Protocols []string `json:"protocols"` Protocols []string `json:"protocols"`
Services map[string][]string `json:"services"` Services map[string][]string `json:"services"`