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.
This commit is contained in:
Norm 2022-11-16 17:52:13 -05:00
parent b958be77b6
commit b18c9b27a6
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE
2 changed files with 8 additions and 8 deletions

View file

@ -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;

View file

@ -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<NodeInfo2Base> => {
] = 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<NodeInfo2Base> => {
software: {
name: 'foundkey',
version: config.version,
repository,
},
protocols: ['activitypub'],
services: {
@ -101,7 +100,7 @@ const nodeinfo2 = async (): Promise<NodeInfo2Base> => {
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<NodeInfo2Base> => {
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');
});