aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-channel.ts32
-rw-r--r--server/models/video/video.ts2
-rw-r--r--server/tests/api/videos/video-channels.ts29
3 files changed, 47 insertions, 16 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index b5bcbdc65..a4231b6b3 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -173,6 +173,10 @@ export type SummaryOptions = {
173 attributes: { 173 attributes: {
174 include: [ 174 include: [
175 [ 175 [
176 literal('(SELECT COUNT(*) FROM "video" WHERE "channelId" = "VideoChannelModel"."id")'),
177 'videosCount'
178 ],
179 [
176 literal( 180 literal(
177 '(' + 181 '(' +
178 `SELECT string_agg(concat_ws('|', t.day, t.views), ',') ` + 182 `SELECT string_agg(concat_ws('|', t.day, t.views), ',') ` +
@@ -544,7 +548,22 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
544 } 548 }
545 549
546 toFormattedJSON (this: MChannelFormattable): VideoChannel { 550 toFormattedJSON (this: MChannelFormattable): VideoChannel {
547 const viewsPerDay = this.get('viewsPerDay') as string 551 const viewsPerDayString = this.get('viewsPerDay') as string
552 const videosCount = this.get('videosCount') as number
553
554 let viewsPerDay: { date: Date, views: number }[]
555
556 if (viewsPerDayString) {
557 viewsPerDay = viewsPerDayString.split(',')
558 .map(v => {
559 const [ dateString, amount ] = v.split('|')
560
561 return {
562 date: new Date(dateString),
563 views: +amount
564 }
565 })
566 }
548 567
549 const actor = this.Actor.toFormattedJSON() 568 const actor = this.Actor.toFormattedJSON()
550 const videoChannel = { 569 const videoChannel = {
@@ -556,15 +575,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
556 createdAt: this.createdAt, 575 createdAt: this.createdAt,
557 updatedAt: this.updatedAt, 576 updatedAt: this.updatedAt,
558 ownerAccount: undefined, 577 ownerAccount: undefined,
559 viewsPerDay: viewsPerDay 578 videosCount,
560 ? viewsPerDay.split(',').map(v => { 579 viewsPerDay
561 const o = v.split('|')
562 return {
563 date: new Date(o[0]),
564 views: +o[1]
565 }
566 })
567 : undefined
568 } 580 }
569 581
570 if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON() 582 if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON()
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index ae2483b2f..1f590c02d 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -500,7 +500,7 @@ export class VideoModel extends Model<VideoModel> {
500 @AllowNull(false) 500 @AllowNull(false)
501 @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy')) 501 @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
502 @Column 502 @Column
503 privacy: number 503 privacy: VideoPrivacy
504 504
505 @AllowNull(false) 505 @AllowNull(false)
506 @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean')) 506 @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean'))
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 89026aba7..e7d9238dd 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -365,7 +365,7 @@ describe('Test video channels', function () {
365 } 365 }
366 }) 366 })
367 367
368 it('Should report correct channel statistics', async function () { 368 it('Should report correct channel views per days', async function () {
369 this.timeout(10000) 369 this.timeout(10000)
370 370
371 { 371 {
@@ -374,14 +374,18 @@ describe('Test video channels', function () {
374 accountName: userInfo.account.name + '@' + userInfo.account.host, 374 accountName: userInfo.account.name + '@' + userInfo.account.host,
375 withStats: true 375 withStats: true
376 }) 376 })
377 res.body.data.forEach((channel: VideoChannel) => { 377
378 const channels: VideoChannel[] = res.body.data
379
380 for (const channel of channels) {
378 expect(channel).to.haveOwnProperty('viewsPerDay') 381 expect(channel).to.haveOwnProperty('viewsPerDay')
379 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today 382 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
380 channel.viewsPerDay.forEach((v: ViewsPerDate) => { 383
384 for (const v of channel.viewsPerDay) {
381 expect(v.date).to.be.an('string') 385 expect(v.date).to.be.an('string')
382 expect(v.views).to.equal(0) 386 expect(v.views).to.equal(0)
383 }) 387 }
384 }) 388 }
385 } 389 }
386 390
387 { 391 {
@@ -402,6 +406,21 @@ describe('Test video channels', function () {
402 } 406 }
403 }) 407 })
404 408
409 it('Should report correct videos count', async function () {
410 const res = await getAccountVideoChannelsList({
411 url: servers[0].url,
412 accountName: userInfo.account.name + '@' + userInfo.account.host,
413 withStats: true
414 })
415 const channels: VideoChannel[] = res.body.data
416
417 const totoChannel = channels.find(c => c.name === 'toto_channel')
418 const rootChannel = channels.find(c => c.name === 'root_channel')
419
420 expect(rootChannel.videosCount).to.equal(1)
421 expect(totoChannel.videosCount).to.equal(0)
422 })
423
405 after(async function () { 424 after(async function () {
406 await cleanupTests(servers) 425 await cleanupTests(servers)
407 }) 426 })