aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-28 18:04:46 +0100
committerChocobozzz <me@florianbigard.com>2018-02-28 18:04:55 +0100
commit09cababd79f9d445aa027c93cdfe823745fa041a (patch)
treef781d6ba78b5c4ce7220dea55f13b21230f203d6 /server/controllers
parent22b59e8099947605085cf65a440f07f37fce6b65 (diff)
downloadPeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.gz
PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.zst
PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.zip
Add stats route
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/inbox.ts2
-rw-r--r--server/controllers/api/config.ts4
-rw-r--r--server/controllers/api/server/index.ts2
-rw-r--r--server/controllers/api/server/stats.ts39
4 files changed, 45 insertions, 2 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index bd0d7a9c8..0354d7833 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -56,6 +56,8 @@ async function inboxController (req: express.Request, res: express.Response, nex
56 specificActor = res.locals.videoChannel 56 specificActor = res.locals.videoChannel
57 } 57 }
58 58
59 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor)
60
59 await processActivities(activities, res.locals.signature.actor, specificActor) 61 await processActivities(activities, res.locals.signature.actor, specificActor)
60 62
61 res.status(204).end() 63 res.status(204).end()
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { omit } from 'lodash' 2import { omit } from 'lodash'
3import { ServerConfig, UserRight } from '../../../shared' 3import { ServerConfig, UserRight } from '../../../shared'
4import { About } from '../../../shared/models/config/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/config/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' 6import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
7import { isSignupAllowed } from '../../helpers/utils' 7import { isSignupAllowed } from '../../helpers/utils'
8import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' 8import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { serverFollowsRouter } from './follows' 2import { serverFollowsRouter } from './follows'
3import { statsRouter } from './stats'
3 4
4const serverRouter = express.Router() 5const serverRouter = express.Router()
5 6
6serverRouter.use('/', serverFollowsRouter) 7serverRouter.use('/', serverFollowsRouter)
8serverRouter.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 @@
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}