mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 11:07:29 -06:00
[feature] Change instance-stats-randomize to instance-stats-mode with multiple options; implement nodeinfo 2.1 (#3734)
* [feature] Change `instance-stats-randomize` to `instance-stats-mode` with multiple options; implement nodeinfo 2.1 * swaggalaggadingdong
This commit is contained in:
parent
e1781ff52e
commit
07d2770995
18 changed files with 283 additions and 77 deletions
|
|
@ -31,9 +31,11 @@ const (
|
|||
hostMetaRel = "lrdd"
|
||||
hostMetaType = "application/xrd+xml"
|
||||
hostMetaTemplate = ".well-known/webfinger?resource={uri}"
|
||||
nodeInfoVersion = "2.0"
|
||||
nodeInfoSoftwareName = "gotosocial"
|
||||
nodeInfoRel = "http://nodeinfo.diaspora.software/ns/schema/" + nodeInfoVersion
|
||||
nodeInfo20Rel = "http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||
nodeInfo21Rel = "http://nodeinfo.diaspora.software/ns/schema/2.1"
|
||||
nodeInfoRepo = "https://github.com/superseriousbusiness/gotosocial"
|
||||
nodeInfoHomepage = "https://docs.gotosocial.org"
|
||||
webfingerProfilePage = "http://webfinger.net/rel/profile-page"
|
||||
webFingerProfilePageContentType = "text/html"
|
||||
webfingerSelf = "self"
|
||||
|
|
@ -56,27 +58,43 @@ func (p *Processor) NodeInfoRelGet(ctx context.Context) (*apimodel.WellKnownResp
|
|||
return &apimodel.WellKnownResponse{
|
||||
Links: []apimodel.Link{
|
||||
{
|
||||
Rel: nodeInfoRel,
|
||||
Href: fmt.Sprintf("%s://%s/nodeinfo/%s", protocol, host, nodeInfoVersion),
|
||||
Rel: nodeInfo20Rel,
|
||||
Href: fmt.Sprintf("%s://%s/nodeinfo/2.0", protocol, host),
|
||||
},
|
||||
{
|
||||
Rel: nodeInfo21Rel,
|
||||
Href: fmt.Sprintf("%s://%s/nodeinfo/2.1", protocol, host),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NodeInfoGet returns a node info struct in response to a node info request.
|
||||
func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserror.WithCode) {
|
||||
// NodeInfoGet returns a node info struct in response to a 2.0 or 2.1 node info request.
|
||||
func (p *Processor) NodeInfoGet(ctx context.Context, schemaVersion string) (*apimodel.Nodeinfo, gtserror.WithCode) {
|
||||
const ()
|
||||
|
||||
var (
|
||||
userCount int
|
||||
postCount int
|
||||
mau int
|
||||
err error
|
||||
)
|
||||
|
||||
if config.GetInstanceStatsRandomize() {
|
||||
switch config.GetInstanceStatsMode() {
|
||||
|
||||
case config.InstanceStatsModeBaffle:
|
||||
// Use randomized stats.
|
||||
stats := p.converter.RandomStats()
|
||||
userCount = int(stats.TotalUsers)
|
||||
postCount = int(stats.Statuses)
|
||||
} else {
|
||||
mau = int(stats.MonthlyActiveUsers)
|
||||
|
||||
case config.InstanceStatsModeZero:
|
||||
// Use zeroed stats
|
||||
// (don't count anything).
|
||||
|
||||
default:
|
||||
// Mode is either "serve" or "default".
|
||||
// Count actual stats.
|
||||
host := config.GetHost()
|
||||
|
||||
|
|
@ -91,8 +109,8 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr
|
|||
}
|
||||
}
|
||||
|
||||
return &apimodel.Nodeinfo{
|
||||
Version: nodeInfoVersion,
|
||||
nodeInfo := &apimodel.Nodeinfo{
|
||||
Version: schemaVersion,
|
||||
Software: apimodel.NodeInfoSoftware{
|
||||
Name: nodeInfoSoftwareName,
|
||||
Version: config.GetSoftwareVersion(),
|
||||
|
|
@ -105,12 +123,20 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr
|
|||
OpenRegistrations: config.GetAccountsRegistrationOpen(),
|
||||
Usage: apimodel.NodeInfoUsage{
|
||||
Users: apimodel.NodeInfoUsers{
|
||||
Total: userCount,
|
||||
Total: userCount,
|
||||
ActiveMonth: mau,
|
||||
},
|
||||
LocalPosts: postCount,
|
||||
},
|
||||
Metadata: nodeInfoMetadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if schemaVersion == "2.0" {
|
||||
nodeInfo.Software.Repository = nodeInfoRepo
|
||||
nodeInfo.Software.Homepage = nodeInfoHomepage
|
||||
}
|
||||
|
||||
return nodeInfo, nil
|
||||
}
|
||||
|
||||
// HostMetaGet returns a host-meta struct in response to a host-meta request.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue