From 47d8e266f16b91fec7e4a15a8372d50c2909c042 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 30 Dec 2020 11:41:36 +0100 Subject: [PATCH] Support activeMonth and activeHalfyear in nodeinfo --- server/controllers/static.ts | 6 ++++-- server/models/account/user.ts | 4 +++- server/tests/misc-endpoints.ts | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/controllers/static.ts b/server/controllers/static.ts index f12f00e1b..bdb9c3041 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -206,7 +206,7 @@ export { async function generateNodeinfo (req: express.Request, res: express.Response) { const { totalVideos } = await VideoModel.getStats() const { totalLocalVideoComments } = await VideoCommentModel.getStats() - const { totalUsers } = await UserModel.getStats() + const { totalUsers, totalMonthlyActiveUsers, totalHalfYearActiveUsers } = await UserModel.getStats() let json = {} if (req.params.version && (req.params.version === '2.0')) { @@ -229,7 +229,9 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { openRegistrations: CONFIG.SIGNUP.ENABLED, usage: { users: { - total: totalUsers + total: totalUsers, + activeMonth: totalMonthlyActiveUsers, + activeHalfyear: totalHalfYearActiveUsers }, localPosts: totalVideos, localComments: totalLocalVideoComments diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 8e437c3be..11003645c 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -794,12 +794,14 @@ export class UserModel extends Model { const totalDailyActiveUsers = await getActiveUsers(1) const totalWeeklyActiveUsers = await getActiveUsers(7) const totalMonthlyActiveUsers = await getActiveUsers(30) + const totalHalfYearActiveUsers = await getActiveUsers(180) return { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, - totalMonthlyActiveUsers + totalMonthlyActiveUsers, + totalHalfYearActiveUsers } } diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts index 698d83328..162b53e18 100644 --- a/server/tests/misc-endpoints.ts +++ b/server/tests/misc-endpoints.ts @@ -110,6 +110,8 @@ describe('Test misc endpoints', function () { }) expect(res.body.software.name).to.equal('peertube') + expect(res.body.usage.users.activeMonth).to.equal(1) + expect(res.body.usage.users.activeHalfyear).to.equal(1) }) }) -- 2.41.0