]>
Commit | Line | Data |
---|---|---|
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 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | |
9 | import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | |
10 | import { cacheRoute } from '../../../middlewares/cache' | |
11 | import { VideoFileModel } from '../../../models/video/video-file' | |
12 | ||
13 | const statsRouter = express.Router() | |
14 | ||
15 | statsRouter.get('/stats', | |
16 | asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.STATS)), | |
17 | asyncMiddleware(getStats) | |
18 | ) | |
19 | ||
20 | async function getStats (req: express.Request, res: express.Response) { | |
21 | const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats() | |
22 | const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats() | |
23 | const { totalUsers } = await UserModel.getStats() | |
24 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() | |
25 | const { totalLocalVideoFilesSize } = await VideoFileModel.getStats() | |
26 | ||
27 | const videosRedundancyStats = await Promise.all( | |
28 | CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => { | |
29 | return VideoRedundancyModel.getStats(r.strategy) | |
30 | .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) | |
31 | }) | |
32 | ) | |
33 | ||
34 | const data: ServerStats = { | |
35 | totalLocalVideos, | |
36 | totalLocalVideoViews, | |
37 | totalLocalVideoFilesSize, | |
38 | totalLocalVideoComments, | |
39 | totalVideos, | |
40 | totalVideoComments, | |
41 | totalUsers, | |
42 | totalInstanceFollowers, | |
43 | totalInstanceFollowing, | |
44 | videosRedundancy: videosRedundancyStats | |
45 | } | |
46 | ||
47 | return res.json(data).end() | |
48 | } | |
49 | ||
50 | // --------------------------------------------------------------------------- | |
51 | ||
52 | export { | |
53 | statsRouter | |
54 | } |