diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-16 14:13:01 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-16 14:13:01 +0200 |
commit | 1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213 (patch) | |
tree | 0f231073a848f3089752fda5fe378ff5b64c229b /server/models | |
parent | af75e2d8df92d5d602e11353536ec6804a25f16f (diff) | |
download | PeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.tar.gz PeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.tar.zst PeerTube-1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213.zip |
Add videos count in channels list
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-channel.ts | 32 | ||||
-rw-r--r-- | server/models/video/video.ts | 2 |
2 files changed, 23 insertions, 11 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')) |