aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-16 14:13:01 +0200
committerChocobozzz <me@florianbigard.com>2020-06-16 14:13:01 +0200
commit1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213 (patch)
tree0f231073a848f3089752fda5fe378ff5b64c229b /server/models/video/video-channel.ts
parentaf75e2d8df92d5d602e11353536ec6804a25f16f (diff)
downloadPeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.tar.gz
PeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.tar.zst
PeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.zip
Add videos count in channels list
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r--server/models/video/video-channel.ts32
1 files changed, 22 insertions, 10 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()