Rename cavage singing func, add import for server
All checks were successful
/ docker (push) Successful in 4m1s

This commit is contained in:
Melody Becker 2025-04-15 14:51:07 +02:00
parent 5e13817563
commit 08f6de0bd7
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
39 changed files with 2035 additions and 364 deletions

View file

@ -38,6 +38,7 @@ func users(w http.ResponseWriter, r *http.Request) {
Type string `json:"type"`
PreferredUsername string `json:"preferredUsername"`
Inbox string `json:"inbox"`
Outboux string `json:"outbox"`
PublicKey OutboundKey `json:"publicKey"`
Published time.Time `json:"published"`
DisplayName string `json:"name"`
@ -82,6 +83,7 @@ func users(w http.ResponseWriter, r *http.Request) {
Type: "Person",
PreferredUsername: user.Username,
Inbox: apUrl + "/inbox",
Outboux: apUrl + "/outbox",
PublicKey: OutboundKey{
Id: apUrl + "#main-key",
Owner: apUrl,

View file

@ -15,6 +15,7 @@ import (
"git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage-new"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
webshared "git.mstar.dev/mstar/linstrom/web/shared"
)
var webfingerResourceRegex = regexp.MustCompile(`acct:(?P<username>[\w-]+)@(?<domain>[\w\.-]+)`)
@ -103,7 +104,23 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
webutils.SendJson(w, &data)
}
func Nodeinfo(w http.ResponseWriter, r *http.Request) {
func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
data := webshared.NodeInfoOverview{
Links: []webshared.NodeInfoLink{
{
Rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
Href: config.GlobalConfig.General.GetFullPublicUrl() + "/nodeinfo/2.1",
},
{
Rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
Href: config.GlobalConfig.General.GetFullPublicUrl() + "/nodeinfo/2.0",
},
},
}
webutils.SendJson(w, data)
}
func NodeInfo21(w http.ResponseWriter, r *http.Request) {
u := dbgen.User
log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).Count()
@ -128,42 +145,81 @@ func Nodeinfo(w http.ResponseWriter, r *http.Request) {
return
}
data := map[string]any{
"version": "2.1",
"software": map[string]string{
"name": "linstrom",
"version": shared.Version,
"homepage": "https://git.mstar.dev/mstar/linstrom",
"repository": "https://git.mstar.dev/mstar/linstrom",
data := webshared.NodeInfo2{
Version: "2.1",
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"),
},
"protocols": []string{"activitypub"},
"services": map[string]any{
"inbound": []string{},
"outbound": []string{},
Protocols: []string{"activitypub"},
Services: map[string][]string{
"inbound": {},
"outbound": {},
},
"openRegistrations": config.GlobalConfig.Admin.AllowRegistration,
"usage": map[string]any{
"users": map[string]any{
"total": userCount,
"activeHalfyear": nil,
"activeMonth": nil,
OpenRegistrations: config.GlobalConfig.Admin.AllowRegistration,
Usage: webshared.NodeInfo2Usage{
Users: webshared.NodeInfo2UsageUsers{
Total: uint(userCount),
ActiveHalfYear: nil,
ActiveMonth: nil,
},
"localPosts": noteCount,
"localComments": 0,
},
"metadata": map[string]any{},
LocalPosts: uint(noteCount),
LocalComments: 0},
Metadata: map[string]any{},
}
webutils.SendJson(w, data)
}
func WellKnownNodeinfo(w http.ResponseWriter, r *http.Request) {
data := map[string]any{
"links": []map[string]any{
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
"href": config.GlobalConfig.General.GetFullPublicUrl() + "/nodeinfo/2.1",
},
},
func NodeInfo20(w http.ResponseWriter, r *http.Request) {
u := dbgen.User
log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).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 user count from db")
}
return
}
data := webshared.NodeInfo2{
Version: "2.1",
Software: webshared.NodeInfo2Software{
Name: "linstrom",
Version: shared.Version,
Homepage: nil,
Repository: nil,
},
Protocols: []string{"activitypub"},
Services: map[string][]string{
"inbound": {},
"outbound": {},
},
OpenRegistrations: config.GlobalConfig.Admin.AllowRegistration,
Usage: webshared.NodeInfo2Usage{
Users: webshared.NodeInfo2UsageUsers{
Total: uint(userCount),
ActiveHalfYear: nil,
ActiveMonth: nil,
},
LocalPosts: uint(noteCount),
LocalComments: 0},
Metadata: map[string]any{},
}
webutils.SendJson(w, data)
}