feat(api): add federation/stats endpoint
This commit is contained in:
parent
164d4a9825
commit
c04d3d22af
|
@ -135,6 +135,7 @@ import * as ep___federation_instances from './endpoints/federation/instances.js'
|
|||
import * as ep___federation_showInstance from './endpoints/federation/show-instance.js';
|
||||
import * as ep___federation_updateRemoteUser from './endpoints/federation/update-remote-user.js';
|
||||
import * as ep___federation_users from './endpoints/federation/users.js';
|
||||
import * as ep___federation_stats from './endpoints/federation/stats.js';
|
||||
import * as ep___following_create from './endpoints/following/create.js';
|
||||
import * as ep___following_delete from './endpoints/following/delete.js';
|
||||
import * as ep___following_invalidate from './endpoints/following/invalidate.js';
|
||||
|
@ -447,6 +448,7 @@ const eps = [
|
|||
['federation/show-instance', ep___federation_showInstance],
|
||||
['federation/update-remote-user', ep___federation_updateRemoteUser],
|
||||
['federation/users', ep___federation_users],
|
||||
['federation/stats', ep___federation_stats],
|
||||
['following/create', ep___following_create],
|
||||
['following/delete', ep___following_delete],
|
||||
['following/invalidate', ep___following_invalidate],
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import { MoreThan } from 'typeorm';
|
||||
import { Instances } from '@/models/index.js';
|
||||
import { awaitAll } from '@/prelude/await-all.js';
|
||||
import define from '../../define.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['federation'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
allowGet: true,
|
||||
cacheSec: 60 * 60,
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const [topSubInstances, topPubInstances] = await Promise.all([
|
||||
Instances.find({
|
||||
where: {
|
||||
followersCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followersCount: 'DESC',
|
||||
},
|
||||
take: 10,
|
||||
}),
|
||||
Instances.find({
|
||||
where: {
|
||||
followingCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followingCount: 'DESC',
|
||||
},
|
||||
take: 10,
|
||||
}),
|
||||
]);
|
||||
|
||||
return await awaitAll({
|
||||
topSubInstances: Instances.packMany(topSubInstances),
|
||||
topPubInstances: Instances.packMany(topPubInstances),
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue