From b18c9b27a65aaefce72058940a7d5209d18e18e2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 16 Nov 2022 17:52:13 -0500 Subject: [PATCH] backend: minor cleanup of nodeinfo.ts Copy over the MONTH constant from the client code and the time constants for active{Halfyear,Month}. Also instead of adding and deleting `respository` from the nodeinfo for version 2.0, only add in the repository URL in the 2.1 endpoint. --- packages/backend/src/const.ts | 3 +++ packages/backend/src/server/nodeinfo.ts | 13 +++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts index 7a56127e5..8dcefc319 100644 --- a/packages/backend/src/const.ts +++ b/packages/backend/src/const.ts @@ -3,6 +3,9 @@ export const SECOND = 1000; export const MINUTE = 60 * SECOND; export const HOUR = 60 * MINUTE; export const DAY = 24 * HOUR; +export const WEEK = 7 * DAY; +export const MONTH = 30 * DAY; +export const YEAR = 365 * DAY; export const USER_ONLINE_THRESHOLD = 10 * MINUTE; export const USER_ACTIVE_THRESHOLD = 3 * DAY; diff --git a/packages/backend/src/server/nodeinfo.ts b/packages/backend/src/server/nodeinfo.ts index 9037b8ab2..6cfdd3561 100644 --- a/packages/backend/src/server/nodeinfo.ts +++ b/packages/backend/src/server/nodeinfo.ts @@ -3,6 +3,7 @@ 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 { MONTH, DAY } from '@/const.js'; const router = new Router(); @@ -23,7 +24,6 @@ type NodeInfo2Base = { software: { name: string; version: string; - repository?: string; // Not used in NodeInfo 2.0; used in 2.1 }; protocols: string[]; services: { @@ -54,8 +54,8 @@ const nodeinfo2 = async (): Promise => { ] = await Promise.all([ fetchMeta(true), Users.count({ where: { host: IsNull() } }), - Users.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 15552000000)) } }), - Users.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 2592000000)) } }), + 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() } }), ]); @@ -65,7 +65,6 @@ const nodeinfo2 = async (): Promise => { software: { name: 'foundkey', version: config.version, - repository, }, protocols: ['activitypub'], services: { @@ -101,7 +100,7 @@ const nodeinfo2 = async (): Promise => { enableDiscordIntegration: meta.enableDiscordIntegration, enableEmail: meta.enableEmail, enableServiceWorker: meta.enableServiceWorker, - proxyAccountName: proxyAccount ? proxyAccount.username : null, + proxyAccountName: proxyAccount?.username ?? null, themeColor: meta.themeColor || '#86b300', }, }; @@ -110,15 +109,13 @@ const nodeinfo2 = async (): Promise => { router.get(nodeinfo2_1path, async ctx => { const base = await nodeinfo2(); - ctx.body = { version: '2.1', ...base }; + ctx.body = { version: '2.1', repository, ...base }; ctx.set('Cache-Control', 'public, max-age=600'); }); router.get(nodeinfo2_0path, async ctx => { const base = await nodeinfo2(); - delete base.software.repository; - ctx.body = { version: '2.0', ...base }; ctx.set('Cache-Control', 'public, max-age=600'); });