1 import * as express from 'express'
2 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
3 import { asyncMiddleware } from '../../../middlewares'
4 import { UserModel } from '../../../models/account/user'
5 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6 import { VideoModel } from '../../../models/video/video'
7 import { VideoCommentModel } from '../../../models/video/video-comment'
9 const statsRouter = express.Router()
11 statsRouter.get('/stats',
12 asyncMiddleware(getStats)
15 async function getStats (req: express.Request, res: express.Response, next: express.NextFunction) {
16 const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats()
17 const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats()
18 const { totalUsers } = await UserModel.getStats()
19 const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
21 const data: ServerStats = {
25 totalLocalVideoComments,
28 totalInstanceFollowers,
29 totalInstanceFollowing
32 return res.json(data).end()
35 // ---------------------------------------------------------------------------