From 747c562837e37f2fa455e8ef62165e9bb4e365f1 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 24 Mar 2020 01:12:30 +0100 Subject: Put channel stats behind withStats flag --- server/controllers/api/accounts.ts | 7 +++++-- server/middlewares/validators/videos/video-channels.ts | 14 ++++++++++++-- server/models/video/video-channel.ts | 1 - 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index f354ccf24..f8d2bad8b 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -17,7 +17,8 @@ import { accountsSortValidator, ensureAuthUserOwnsAccountValidator, videoChannelsSortValidator, - videosSortValidator + videosSortValidator, + videoChannelStatsValidator } from '../../middlewares/validators' import { AccountModel } from '../../models/account/account' import { AccountVideoRateModel } from '../../models/account/account-video-rate' @@ -56,6 +57,7 @@ accountsRouter.get('/:accountName/videos', accountsRouter.get('/:accountName/video-channels', asyncMiddleware(accountNameWithHostGetValidator), + videoChannelStatsValidator, paginationValidator, videoChannelsSortValidator, setDefaultSort, @@ -116,7 +118,8 @@ async function listAccountChannels (req: express.Request, res: express.Response) accountId: res.locals.account.id, start: req.query.start, count: req.query.count, - sort: req.query.sort + sort: req.query.sort, + withStats: req.query.withStats } const resultList = await VideoChannelModel.listByAccount(options) diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index ebce14714..882fb2b84 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import { body, param } from 'express-validator' +import { body, param, query } from 'express-validator' import { UserRight } from '../../../../shared' import { isVideoChannelDescriptionValid, @@ -128,6 +128,15 @@ const localVideoChannelValidator = [ } ] +const videoChannelStatsValidator = [ + query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (areValidationErrors(req, res)) return + return next() + } +] + // --------------------------------------------------------------------------- export { @@ -135,7 +144,8 @@ export { videoChannelsUpdateValidator, videoChannelsRemoveValidator, videoChannelsNameWithHostValidator, - localVideoChannelValidator + localVideoChannelValidator, + videoChannelStatsValidator } // --------------------------------------------------------------------------- diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 128915af3..5e6541837 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -412,7 +412,6 @@ export class VideoChannelModel extends Model { const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] - options.withStats = true // TODO: remove beyond after initial tests if (options.withStats) { scopes.push({ method: [ ScopeNames.WITH_STATS, { daysPrior: 30 } as AvailableWithStatsOptions ] -- cgit v1.2.3