feat(api): add federation/stats endpoint
This commit is contained in:
parent
164d4a9825
commit
c04d3d22af
2 changed files with 51 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue