Adjust totalModerators and totalAdmins too

This commit is contained in:
2025-03-19 10:09:26 +09:00
parent 66ae7583d2
commit 40c7031090
3 changed files with 29 additions and 16 deletions

35
main.js
View File

@@ -1,14 +1,6 @@
async function register ({ async function register({ registerHook }) {
registerHook,
registerSetting,
settingsManager,
storageManager,
videoCategoryManager,
videoLicenceManager,
videoLanguageManager,
}) {
registerHook({ registerHook({
target: 'filter:api.server.stats.get.result', target: "filter:api.server.stats.get.result",
handler: (data) => { handler: (data) => {
if (!data) return {}; if (!data) return {};
@@ -17,26 +9,47 @@ async function register ({
totalDailyActiveUsers, totalDailyActiveUsers,
totalWeeklyActiveUsers, totalWeeklyActiveUsers,
totalMonthlyActiveUsers, totalMonthlyActiveUsers,
totalModerators,
totalAdmins,
} = data; } = data;
// Remove one from total users if there are more than one
if (totalUsers > 1) { if (totalUsers > 1) {
totalUsers = totalUsers - 1; totalUsers = totalUsers - 1;
} }
// Remove one from the moderator count if there are more than one
if (totalModerators > 1) {
totalModerators = totalModerators - 1;
}
// Remove one from the admin count if there are more than one
if (totalAdmins > 1) {
totalAdmins = totalAdmins - 1;
}
// Adjust daily active user count if there are more listed than there
// are total users.
if (totalDailyActiveUsers > totalUsers) { if (totalDailyActiveUsers > totalUsers) {
totalDailyActiveUsers = totalUsers; totalDailyActiveUsers = totalUsers;
} }
// Adjust weekly active user count if there are more listed than there
// are total users.
if (totalWeeklyActiveUsers > totalUsers) { if (totalWeeklyActiveUsers > totalUsers) {
totalWeeklyActiveUsers = totalUsers; totalWeeklyActiveUsers = totalUsers;
} }
// Adjust monthly active user count if there are more listed than there
// are total users.
if (totalMonthlyActiveUsers > totalUsers) { if (totalMonthlyActiveUsers > totalUsers) {
totalMonthlyActiveUsers = totalUsers; totalMonthlyActiveUsers = totalUsers;
} }
return { return {
...data, ...data,
totalAdmins,
totalModerators,
totalUsers, totalUsers,
totalDailyActiveUsers, totalDailyActiveUsers,
totalWeeklyActiveUsers, totalWeeklyActiveUsers,
@@ -46,7 +59,7 @@ async function register ({
}); });
} }
async function unregister () { async function unregister() {
return; return;
} }

5
package-lock.json generated
View File

@@ -1,12 +1,13 @@
{ {
"name": "peertube-plugin-hide-root-user", "name": "peertube-plugin-hide-root-user",
"version": "0.5.0", "version": "0.6.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "peertube-plugin-hide-root-user", "name": "peertube-plugin-hide-root-user",
"version": "0.5.0" "version": "0.6.0",
"license": "AGPL-3.0-or-later"
} }
} }
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "peertube-plugin-hide-root-user", "name": "peertube-plugin-hide-root-user",
"description": "Prevents the \"root\" user from showing up in your PeerTube server's public-facing stats. Useful only when the root account isn't actually being used on your instance.", "description": "Prevents the \"root\" user from showing up in your PeerTube server's public-facing stats. Useful only when the root account isn't actually being used on your instance.",
"version": "0.5.0", "version": "0.6.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"author": { "author": {
"name": "Dave Jansen", "name": "Dave Jansen",
@@ -10,7 +10,7 @@
}, },
"bugs": "https://git.davejansen.com/davejansen/peertube-plugin-hide-root-user/issues", "bugs": "https://git.davejansen.com/davejansen/peertube-plugin-hide-root-user/issues",
"engine": { "engine": {
"peertube": ">=6.0.0" "peertube": ">=7.0.0"
}, },
"homepage": "https://git.davejansen.com/davejansen/peertube-plugin-hide-root-user", "homepage": "https://git.davejansen.com/davejansen/peertube-plugin-hide-root-user",
"keywords": [ "keywords": [
@@ -18,7 +18,6 @@
"plugin" "plugin"
], ],
"library": "./main.js", "library": "./main.js",
"css": [], "css": [],
"clientScripts": [], "clientScripts": [],
"staticDirs": {}, "staticDirs": {},