Put channel stats behind withStats flag
authorRigel Kent <sendmemail@rigelk.eu>
Tue, 24 Mar 2020 00:12:30 +0000 (01:12 +0100)
committerChocobozzz <chocobozzz@cpy.re>
Tue, 31 Mar 2020 08:29:24 +0000 (10:29 +0200)
client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts
client/src/app/shared/video-channel/video-channel.model.ts
client/src/app/shared/video-channel/video-channel.service.ts
server/controllers/api/accounts.ts
server/middlewares/validators/videos/video-channels.ts
server/models/video/video-channel.ts

index eeab3a8dd60c9b84ebfac61674c1d0c784b83039..27a1576213cb853be9797a877ad6783f19a8355e 100644 (file)
@@ -57,7 +57,7 @@ export class MyAccountVideoChannelsComponent implements OnInit {
             min: Math.max(0, this.videoChannelsMinimumDailyViews - (3 * this.videoChannelsMaximumDailyViews / 100)),
             max: this.videoChannelsMaximumDailyViews
           }
-        }],
+        }]
       },
       layout: {
         padding: {
@@ -68,7 +68,7 @@ export class MyAccountVideoChannelsComponent implements OnInit {
         }
       },
       elements: {
-        point:{
+        point: {
           radius: 0
         }
       },
@@ -76,14 +76,12 @@ export class MyAccountVideoChannelsComponent implements OnInit {
         mode: 'index',
         intersect: false,
         custom: function (tooltip: any) {
-          if (!tooltip) return;
-          // disable displaying the color box;
-          tooltip.displayColors = false;
+          if (!tooltip) return
+          // disable displaying the color box
+          tooltip.displayColors = false
         },
         callbacks: {
-          label: function (tooltip: any, data: any) {
-            return `${tooltip.value} views`;
-          }
+          label: (tooltip: any, data: any) => `${tooltip.value} views`
         }
       },
       hover: {
@@ -124,7 +122,7 @@ export class MyAccountVideoChannelsComponent implements OnInit {
 
   private loadVideoChannels () {
     this.authService.userInformationLoaded
-        .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account)))
+        .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account, null, true)))
         .subscribe(res => {
           this.videoChannels = res.data
           this.videoChannelsData = this.videoChannels.map(v => ({
index ee3288d7a55d5873df3072a008c5596f554f6685..c93af0ca50916e91e120d9fd94ba1aa65340e266 100644 (file)
@@ -25,7 +25,7 @@ export class VideoChannel extends Actor implements ServerVideoChannel {
     this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
 
     if (hash.viewsPerDay) {
-      this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date)}))
+      this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
     }
 
     if (hash.ownerAccount) {
index adb4f48192e426c3dfb9c428e4cd1489d13d3dd6..0e036bda766b4da49066339d9c43a5ff49039055 100644 (file)
@@ -44,13 +44,18 @@ export class VideoChannelService {
                )
   }
 
-  listAccountVideoChannels (account: Account, componentPagination?: ComponentPaginationLight): Observable<ResultList<VideoChannel>> {
+  listAccountVideoChannels (
+    account: Account,
+    componentPagination?: ComponentPaginationLight,
+    withStats = false
+  ): Observable<ResultList<VideoChannel>> {
     const pagination = componentPagination
       ? this.restService.componentPaginationToRestPagination(componentPagination)
       : { start: 0, count: 20 }
 
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination)
+    params = params.set('withStats', withStats + '')
 
     const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels'
     return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params })
index f354ccf24e6540b28383015dda1a9c0148a3d81d..f8d2bad8bc79a9ac9363c1f9eeb34cec2ed6ef85 100644 (file)
@@ -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)
index ebce14714785ba3ef946cb608723728ef28df695..882fb2b843a653dbe5fa02f7c55a26ef253dd9c3 100644 (file)
@@ -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
 }
 
 // ---------------------------------------------------------------------------
index 128915af31a9d7d0b727c55946f9e7d7105313b6..5e65418378273de992cec9029c1a7679eabd4877 100644 (file)
@@ -412,7 +412,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
 
     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 ]