aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r--server/models/video/video-channel.ts78
1 files changed, 39 insertions, 39 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 0c8aef18f..178878c55 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -1,5 +1,4 @@
1import * as Bluebird from 'bluebird' 1import { FindOptions, Includeable, literal, Op, ScopeOptions } from 'sequelize'
2import { FindOptions, literal, Op, ScopeOptions } from 'sequelize'
3import { 2import {
4 AllowNull, 3 AllowNull,
5 BeforeDestroy, 4 BeforeDestroy,
@@ -119,30 +118,31 @@ export type SummaryOptions = {
119 } 118 }
120 }, 119 },
121 [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { 120 [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => {
121 const include: Includeable[] = [
122 {
123 attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
124 model: ActorModel.unscoped(),
125 required: options.actorRequired ?? true,
126 include: [
127 {
128 attributes: [ 'host' ],
129 model: ServerModel.unscoped(),
130 required: false
131 },
132 {
133 model: AvatarModel.unscoped(),
134 required: false
135 }
136 ]
137 }
138 ]
139
122 const base: FindOptions = { 140 const base: FindOptions = {
123 attributes: [ 'id', 'name', 'description', 'actorId' ], 141 attributes: [ 'id', 'name', 'description', 'actorId' ]
124 include: [
125 {
126 attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
127 model: ActorModel.unscoped(),
128 required: options.actorRequired ?? true,
129 include: [
130 {
131 attributes: [ 'host' ],
132 model: ServerModel.unscoped(),
133 required: false
134 },
135 {
136 model: AvatarModel.unscoped(),
137 required: false
138 }
139 ]
140 }
141 ]
142 } 142 }
143 143
144 if (options.withAccount === true) { 144 if (options.withAccount === true) {
145 base.include.push({ 145 include.push({
146 model: AccountModel.scope({ 146 model: AccountModel.scope({
147 method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ] 147 method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ]
148 }), 148 }),
@@ -150,6 +150,8 @@ export type SummaryOptions = {
150 }) 150 })
151 } 151 }
152 152
153 base.include = include
154
153 return base 155 return base
154 }, 156 },
155 [ScopeNames.WITH_ACCOUNT]: { 157 [ScopeNames.WITH_ACCOUNT]: {
@@ -221,7 +223,7 @@ export type SummaryOptions = {
221 } 223 }
222 ] 224 ]
223}) 225})
224export class VideoChannelModel extends Model<VideoChannelModel> { 226export class VideoChannelModel extends Model {
225 227
226 @AllowNull(false) 228 @AllowNull(false)
227 @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name')) 229 @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name'))
@@ -328,18 +330,17 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
328 order: getSort(parameters.sort) 330 order: getSort(parameters.sort)
329 } 331 }
330 332
331 const scopes = {
332 method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
333 }
334 return VideoChannelModel 333 return VideoChannelModel
335 .scope(scopes) 334 .scope({
335 method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
336 })
336 .findAndCountAll(query) 337 .findAndCountAll(query)
337 .then(({ rows, count }) => { 338 .then(({ rows, count }) => {
338 return { total: count, data: rows } 339 return { total: count, data: rows }
339 }) 340 })
340 } 341 }
341 342
342 static listLocalsForSitemap (sort: string): Bluebird<MChannelActor[]> { 343 static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> {
343 const query = { 344 const query = {
344 attributes: [ ], 345 attributes: [ ],
345 offset: 0, 346 offset: 0,
@@ -391,11 +392,10 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
391 } 392 }
392 } 393 }
393 394
394 const scopes = {
395 method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ]
396 }
397 return VideoChannelModel 395 return VideoChannelModel
398 .scope(scopes) 396 .scope({
397 method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ]
398 })
399 .findAndCountAll(query) 399 .findAndCountAll(query)
400 .then(({ rows, count }) => { 400 .then(({ rows, count }) => {
401 return { total: count, data: rows } 401 return { total: count, data: rows }
@@ -457,13 +457,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
457 }) 457 })
458 } 458 }
459 459
460 static loadByIdAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> { 460 static loadByIdAndPopulateAccount (id: number): Promise<MChannelAccountDefault> {
461 return VideoChannelModel.unscoped() 461 return VideoChannelModel.unscoped()
462 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 462 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
463 .findByPk(id) 463 .findByPk(id)
464 } 464 }
465 465
466 static loadByIdAndAccount (id: number, accountId: number): Bluebird<MChannelAccountDefault> { 466 static loadByIdAndAccount (id: number, accountId: number): Promise<MChannelAccountDefault> {
467 const query = { 467 const query = {
468 where: { 468 where: {
469 id, 469 id,
@@ -476,13 +476,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
476 .findOne(query) 476 .findOne(query)
477 } 477 }
478 478
479 static loadAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> { 479 static loadAndPopulateAccount (id: number): Promise<MChannelAccountDefault> {
480 return VideoChannelModel.unscoped() 480 return VideoChannelModel.unscoped()
481 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 481 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
482 .findByPk(id) 482 .findByPk(id)
483 } 483 }
484 484
485 static loadByUrlAndPopulateAccount (url: string): Bluebird<MChannelAccountDefault> { 485 static loadByUrlAndPopulateAccount (url: string): Promise<MChannelAccountDefault> {
486 const query = { 486 const query = {
487 include: [ 487 include: [
488 { 488 {
@@ -508,7 +508,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
508 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) 508 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
509 } 509 }
510 510
511 static loadLocalByNameAndPopulateAccount (name: string): Bluebird<MChannelAccountDefault> { 511 static loadLocalByNameAndPopulateAccount (name: string): Promise<MChannelAccountDefault> {
512 const query = { 512 const query = {
513 include: [ 513 include: [
514 { 514 {
@@ -527,7 +527,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
527 .findOne(query) 527 .findOne(query)
528 } 528 }
529 529
530 static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird<MChannelAccountDefault> { 530 static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise<MChannelAccountDefault> {
531 const query = { 531 const query = {
532 include: [ 532 include: [
533 { 533 {
@@ -552,7 +552,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
552 .findOne(query) 552 .findOne(query)
553 } 553 }
554 554
555 static loadAndPopulateAccountAndVideos (id: number): Bluebird<MChannelActorAccountDefaultVideos> { 555 static loadAndPopulateAccountAndVideos (id: number): Promise<MChannelActorAccountDefaultVideos> {
556 const options = { 556 const options = {
557 include: [ 557 include: [
558 VideoModel 558 VideoModel