From cc0915775bcd5a3d6024db5cbf3e9a463d558256 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 5 Jun 2023 22:23:59 +0200 Subject: [PATCH] server: add webhook stat to nodeinfo This will show the number of active web hooks in the node info. This is desired to be able to gauge webhook usage in Foundkey. Changelog: Added --- packages/backend/src/server/nodeinfo.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/nodeinfo.ts b/packages/backend/src/server/nodeinfo.ts index 6ce55239c..380383ee1 100644 --- a/packages/backend/src/server/nodeinfo.ts +++ b/packages/backend/src/server/nodeinfo.ts @@ -2,7 +2,7 @@ import Router from '@koa/router'; import { IsNull, MoreThan } from 'typeorm'; import config from '@/config/index.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; -import { Users, Notes } from '@/models/index.js'; +import { Users, Notes, Webhooks } from '@/models/index.js'; import { MONTH, DAY } from '@/const.js'; const router = new Router(); @@ -52,12 +52,14 @@ const nodeinfo2 = async (): Promise => { activeHalfyear, activeMonth, localPosts, + activeWebhooks, ] = await Promise.all([ fetchMeta(true), Users.count({ where: { host: IsNull() } }), Users.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 180 * DAY)) } }), Users.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - MONTH)) } }), Notes.count({ where: { userHost: IsNull() } }), + Webhooks.countBy({ active: true }), ]); const proxyAccount = meta.proxyAccountId ? await Users.pack(meta.proxyAccountId).catch(() => null) : null; @@ -100,6 +102,7 @@ const nodeinfo2 = async (): Promise => { enableEmail: meta.enableEmail, proxyAccountName: proxyAccount?.username ?? null, themeColor: meta.themeColor || '#86b300', + activeWebhooks, }, }; };