diff --git a/config/config.go b/config/config.go index 83399bd..f6cf846 100644 --- a/config/config.go +++ b/config/config.go @@ -107,6 +107,8 @@ type ConfigSelf struct { ServerActorDisplayName string `toml:"server_actor_display_name"` // The name of the server provided via nodeinfo 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 @@ -212,6 +214,7 @@ var defaultConfig Config = Config{ Self: ConfigSelf{ ServerActorDisplayName: "Server actor", ServerDisplayName: "Linstrom", + ServerDescription: "A social media server running Linstrom", }, S3: ConfigS3{ KeyId: "Example key ID", diff --git a/web/public/api/webfinger.go b/web/public/api/webfinger.go index 54da6f5..30ae81b 100644 --- a/web/public/api/webfinger.go +++ b/web/public/api/webfinger.go @@ -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) diff --git a/web/shared/Nodeinfo.go b/web/shared/Nodeinfo.go index 8c54a81..6b90b79 100644 --- a/web/shared/Nodeinfo.go +++ b/web/shared/Nodeinfo.go @@ -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"`