]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/server/stats.ts
Bold dependencies part in production guide
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / stats.ts
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'
8
9 const statsRouter = express.Router()
10
11 statsRouter.get('/stats',
12 asyncMiddleware(getStats)
13 )
14
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()
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
37 export {
38 statsRouter
39 }