diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-28 18:04:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-28 18:04:55 +0100 |
commit | 09cababd79f9d445aa027c93cdfe823745fa041a (patch) | |
tree | f781d6ba78b5c4ce7220dea55f13b21230f203d6 /server/controllers/api | |
parent | 22b59e8099947605085cf65a440f07f37fce6b65 (diff) | |
download | PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.gz PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.zst PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.zip |
Add stats route
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/config.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/server/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/server/stats.ts | 39 |
3 files changed, 43 insertions, 2 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 7ef0c19e3..427125810 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { omit } from 'lodash' | 2 | import { omit } from 'lodash' |
3 | import { ServerConfig, UserRight } from '../../../shared' | 3 | import { ServerConfig, UserRight } from '../../../shared' |
4 | import { About } from '../../../shared/models/config/about.model' | 4 | import { About } from '../../../shared/models/server/about.model' |
5 | import { CustomConfig } from '../../../shared/models/config/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | 6 | import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' |
7 | import { isSignupAllowed } from '../../helpers/utils' | 7 | import { isSignupAllowed } from '../../helpers/utils' |
8 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' | 8 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' |
diff --git a/server/controllers/api/server/index.ts b/server/controllers/api/server/index.ts index 8dc1a0031..850a52cdb 100644 --- a/server/controllers/api/server/index.ts +++ b/server/controllers/api/server/index.ts | |||
@@ -1,9 +1,11 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { serverFollowsRouter } from './follows' | 2 | import { serverFollowsRouter } from './follows' |
3 | import { statsRouter } from './stats' | ||
3 | 4 | ||
4 | const serverRouter = express.Router() | 5 | const serverRouter = express.Router() |
5 | 6 | ||
6 | serverRouter.use('/', serverFollowsRouter) | 7 | serverRouter.use('/', serverFollowsRouter) |
8 | serverRouter.use('/', statsRouter) | ||
7 | 9 | ||
8 | // --------------------------------------------------------------------------- | 10 | // --------------------------------------------------------------------------- |
9 | 11 | ||
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts new file mode 100644 index 000000000..6f4fe938c --- /dev/null +++ b/server/controllers/api/server/stats.ts | |||
@@ -0,0 +1,39 @@ | |||
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 | } | ||