@@ -6,7 +6,9 @@ package misc
66
77import (
88 "net/http"
9+ "time"
910
11+ user_model "code.gitea.io/gitea/models/user"
1012 "code.gitea.io/gitea/modules/context"
1113 "code.gitea.io/gitea/modules/setting"
1214 "code.gitea.io/gitea/modules/structs"
@@ -23,6 +25,16 @@ func NodeInfo(ctx *context.APIContext) {
2325 // "200":
2426 // "$ref": "#/responses/NodeInfo"
2527
28+ infoUsageUsers := structs.NodeInfoUsageUsers {}
29+ if setting .Federation .ShareUserStatistics {
30+ infoUsageUsers .Total = int (user_model .CountUsers (nil ))
31+ now := time .Now ()
32+ timeOneMonthAgo := now .AddDate (0 , - 1 , 0 ).Unix ()
33+ timeHaveYearAgo := now .AddDate (0 , - 6 , 0 ).Unix ()
34+ infoUsageUsers .ActiveMonth = int (user_model .CountUsers (& user_model.CountUserFilter {LastLoginSince : & timeOneMonthAgo }))
35+ infoUsageUsers .ActiveHalfyear = int (user_model .CountUsers (& user_model.CountUserFilter {LastLoginSince : & timeHaveYearAgo }))
36+ }
37+
2638 nodeInfo := & structs.NodeInfo {
2739 Version : "2.1" ,
2840 Software : structs.NodeInfoSoftware {
@@ -38,7 +50,7 @@ func NodeInfo(ctx *context.APIContext) {
3850 },
3951 OpenRegistrations : setting .Service .ShowRegistrationButton ,
4052 Usage : structs.NodeInfoUsage {
41- Users : structs. NodeInfoUsageUsers {} ,
53+ Users : infoUsageUsers ,
4254 },
4355 }
4456 ctx .JSON (http .StatusOK , nodeInfo )
0 commit comments