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:
parent
22b59e8099
commit
09cababd79
26 changed files with 268 additions and 42 deletions
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
|
39
server/controllers/api/server/stats.ts
Normal file
39
server/controllers/api/server/stats.ts
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue