]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/server/stats.ts
Add stats route
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / stats.ts
CommitLineData
09cababd
C
1import * as express from 'express'
2import { ServerStats } from '../../../../shared/models/server/server-stats.model'
3import { asyncMiddleware } from '../../../middlewares'
4import { UserModel } from '../../../models/account/user'
5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { VideoModel } from '../../../models/video/video'
7import { VideoCommentModel } from '../../../models/video/video-comment'
8
9const statsRouter = express.Router()
10
11statsRouter.get('/stats',
12 asyncMiddleware(getStats)
13)
14
15async 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()
20
21 const data: ServerStats = {
22 totalLocalVideos,
23 totalLocalVideoViews,
24 totalVideos,
25 totalLocalVideoComments,
26 totalVideoComments,
27 totalUsers,
28 totalInstanceFollowers,
29 totalInstanceFollowing
30 }
31
32 return res.json(data).end()
33}
34
35// ---------------------------------------------------------------------------
36
37export {
38 statsRouter
39}