From 09cababd79f9d445aa027c93cdfe823745fa041a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Feb 2018 18:04:46 +0100 Subject: Add stats route --- server/controllers/activitypub/inbox.ts | 2 ++ server/controllers/api/config.ts | 4 ++-- server/controllers/api/server/index.ts | 2 ++ server/controllers/api/server/stats.ts | 39 +++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 server/controllers/api/server/stats.ts (limited to 'server/controllers') 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 specificActor = res.locals.videoChannel } + logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor) + await processActivities(activities, res.locals.signature.actor, specificActor) 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 @@ 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' 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 @@ import * as express from 'express' import { serverFollowsRouter } from './follows' +import { statsRouter } from './stats' const serverRouter = express.Router() serverRouter.use('/', serverFollowsRouter) +serverRouter.use('/', statsRouter) // --------------------------------------------------------------------------- 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 @@ +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 +} -- cgit v1.2.3