1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add stats route

This commit is contained in:
Chocobozzz 2018-02-28 18:04:46 +01:00
parent 22b59e8099
commit 09cababd79
No known key found for this signature in database
GPG key ID: 583A612D890159BE
26 changed files with 268 additions and 42 deletions

View file

@ -1,8 +1,8 @@
import * as express from 'express'
import { omit } from 'lodash'
import { ServerConfig, UserRight } from '../../../shared'
import { About } from '../../../shared/models/config/about.model'
import { CustomConfig } from '../../../shared/models/config/custom-config.model'
import { About } from '../../../shared/models/server/about.model'
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
import { isSignupAllowed } from '../../helpers/utils'
import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'

View file

@ -1,9 +1,11 @@
import * as express from 'express'
import { serverFollowsRouter } from './follows'
import { statsRouter } from './stats'
const serverRouter = express.Router()
serverRouter.use('/', serverFollowsRouter)
serverRouter.use('/', statsRouter)
// ---------------------------------------------------------------------------

View file

@ -0,0 +1,39 @@
import * as express from 'express'
import { ServerStats } from '../../../../shared/models/server/server-stats.model'
import { asyncMiddleware } from '../../../middlewares'
import { UserModel } from '../../../models/account/user'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
const statsRouter = express.Router()
statsRouter.get('/stats',
asyncMiddleware(getStats)
)
async function getStats (req: express.Request, res: express.Response, next: express.NextFunction) {
const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats()
const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats()
const { totalUsers } = await UserModel.getStats()
const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
const data: ServerStats = {
totalLocalVideos,
totalLocalVideoViews,
totalVideos,
totalLocalVideoComments,
totalVideoComments,
totalUsers,
totalInstanceFollowers,
totalInstanceFollowing
}
return res.json(data).end()
}
// ---------------------------------------------------------------------------
export {
statsRouter
}