aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-06 17:01:35 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-04-08 10:07:53 +0200
commit2cb03dc1f4e01ba491c36caff30c33fe9c5bad89 (patch)
tree08a8706d105ea1e280339c02b9e2b1dc1edb0ff9 /server/models/video/video-channel.ts
parentf479685678406a5df864d89615b33d29085ebfc6 (diff)
downloadPeerTube-2cb03dc1f4e01ba491c36caff30c33fe9c5bad89.tar.gz
PeerTube-2cb03dc1f4e01ba491c36caff30c33fe9c5bad89.tar.zst
PeerTube-2cb03dc1f4e01ba491c36caff30c33fe9c5bad89.zip
Add banners support
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r--server/models/video/video-channel.ts88
1 files changed, 45 insertions, 43 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 815fb16c0..74885edfb 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -28,10 +28,9 @@ import {
28import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' 28import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
29import { sendDeleteActor } from '../../lib/activitypub/send' 29import { sendDeleteActor } from '../../lib/activitypub/send'
30import { 30import {
31 MChannelAccountDefault,
32 MChannelActor, 31 MChannelActor,
33 MChannelActorAccountDefaultVideos,
34 MChannelAP, 32 MChannelAP,
33 MChannelBannerAccountDefault,
35 MChannelFormattable, 34 MChannelFormattable,
36 MChannelSummaryFormattable 35 MChannelSummaryFormattable
37} from '../../types/models/video' 36} from '../../types/models/video'
@@ -49,6 +48,7 @@ export enum ScopeNames {
49 SUMMARY = 'SUMMARY', 48 SUMMARY = 'SUMMARY',
50 WITH_ACCOUNT = 'WITH_ACCOUNT', 49 WITH_ACCOUNT = 'WITH_ACCOUNT',
51 WITH_ACTOR = 'WITH_ACTOR', 50 WITH_ACTOR = 'WITH_ACTOR',
51 WITH_ACTOR_BANNER = 'WITH_ACTOR_BANNER',
52 WITH_VIDEOS = 'WITH_VIDEOS', 52 WITH_VIDEOS = 'WITH_VIDEOS',
53 WITH_STATS = 'WITH_STATS' 53 WITH_STATS = 'WITH_STATS'
54} 54}
@@ -168,6 +168,20 @@ export type SummaryOptions = {
168 ActorModel 168 ActorModel
169 ] 169 ]
170 }, 170 },
171 [ScopeNames.WITH_ACTOR_BANNER]: {
172 include: [
173 {
174 model: ActorModel,
175 include: [
176 {
177 model: ActorImageModel,
178 required: false,
179 as: 'Banner'
180 }
181 ]
182 }
183 ]
184 },
171 [ScopeNames.WITH_VIDEOS]: { 185 [ScopeNames.WITH_VIDEOS]: {
172 include: [ 186 include: [
173 VideoModel 187 VideoModel
@@ -442,7 +456,7 @@ export class VideoChannelModel extends Model {
442 where 456 where
443 } 457 }
444 458
445 const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] 459 const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR_BANNER ]
446 460
447 if (options.withStats === true) { 461 if (options.withStats === true) {
448 scopes.push({ 462 scopes.push({
@@ -458,32 +472,13 @@ export class VideoChannelModel extends Model {
458 }) 472 })
459 } 473 }
460 474
461 static loadByIdAndPopulateAccount (id: number): Promise<MChannelAccountDefault> { 475 static loadAndPopulateAccount (id: number): Promise<MChannelBannerAccountDefault> {
462 return VideoChannelModel.unscoped()
463 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
464 .findByPk(id)
465 }
466
467 static loadByIdAndAccount (id: number, accountId: number): Promise<MChannelAccountDefault> {
468 const query = {
469 where: {
470 id,
471 accountId
472 }
473 }
474
475 return VideoChannelModel.unscoped()
476 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
477 .findOne(query)
478 }
479
480 static loadAndPopulateAccount (id: number): Promise<MChannelAccountDefault> {
481 return VideoChannelModel.unscoped() 476 return VideoChannelModel.unscoped()
482 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 477 .scope([ ScopeNames.WITH_ACTOR_BANNER, ScopeNames.WITH_ACCOUNT ])
483 .findByPk(id) 478 .findByPk(id)
484 } 479 }
485 480
486 static loadByUrlAndPopulateAccount (url: string): Promise<MChannelAccountDefault> { 481 static loadByUrlAndPopulateAccount (url: string): Promise<MChannelBannerAccountDefault> {
487 const query = { 482 const query = {
488 include: [ 483 include: [
489 { 484 {
@@ -491,7 +486,14 @@ export class VideoChannelModel extends Model {
491 required: true, 486 required: true,
492 where: { 487 where: {
493 url 488 url
494 } 489 },
490 include: [
491 {
492 model: ActorImageModel,
493 required: false,
494 as: 'Banner'
495 }
496 ]
495 } 497 }
496 ] 498 ]
497 } 499 }
@@ -509,7 +511,7 @@ export class VideoChannelModel extends Model {
509 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) 511 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
510 } 512 }
511 513
512 static loadLocalByNameAndPopulateAccount (name: string): Promise<MChannelAccountDefault> { 514 static loadLocalByNameAndPopulateAccount (name: string): Promise<MChannelBannerAccountDefault> {
513 const query = { 515 const query = {
514 include: [ 516 include: [
515 { 517 {
@@ -518,17 +520,24 @@ export class VideoChannelModel extends Model {
518 where: { 520 where: {
519 preferredUsername: name, 521 preferredUsername: name,
520 serverId: null 522 serverId: null
521 } 523 },
524 include: [
525 {
526 model: ActorImageModel,
527 required: false,
528 as: 'Banner'
529 }
530 ]
522 } 531 }
523 ] 532 ]
524 } 533 }
525 534
526 return VideoChannelModel.unscoped() 535 return VideoChannelModel.unscoped()
527 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 536 .scope([ ScopeNames.WITH_ACCOUNT ])
528 .findOne(query) 537 .findOne(query)
529 } 538 }
530 539
531 static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise<MChannelAccountDefault> { 540 static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise<MChannelBannerAccountDefault> {
532 const query = { 541 const query = {
533 include: [ 542 include: [
534 { 543 {
@@ -542,6 +551,11 @@ export class VideoChannelModel extends Model {
542 model: ServerModel, 551 model: ServerModel,
543 required: true, 552 required: true,
544 where: { host } 553 where: { host }
554 },
555 {
556 model: ActorImageModel,
557 required: false,
558 as: 'Banner'
545 } 559 }
546 ] 560 ]
547 } 561 }
@@ -549,22 +563,10 @@ export class VideoChannelModel extends Model {
549 } 563 }
550 564
551 return VideoChannelModel.unscoped() 565 return VideoChannelModel.unscoped()
552 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 566 .scope([ ScopeNames.WITH_ACCOUNT ])
553 .findOne(query) 567 .findOne(query)
554 } 568 }
555 569
556 static loadAndPopulateAccountAndVideos (id: number): Promise<MChannelActorAccountDefaultVideos> {
557 const options = {
558 include: [
559 VideoModel
560 ]
561 }
562
563 return VideoChannelModel.unscoped()
564 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ])
565 .findByPk(id, options)
566 }
567
568 toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary { 570 toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary {
569 const actor = this.Actor.toFormattedSummaryJSON() 571 const actor = this.Actor.toFormattedSummaryJSON()
570 572