diff options
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r-- | server/models/video/video-channel.ts | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 183e7448c..9aa271711 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction } from 'sequelize' | 1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction, WhereOptions } from 'sequelize' |
2 | import { | 2 | import { |
3 | AllowNull, | 3 | AllowNull, |
4 | BeforeDestroy, | 4 | BeforeDestroy, |
@@ -17,7 +17,6 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { setAsUpdated } from '@server/helpers/database-utils' | ||
21 | import { MAccountActor } from '@server/types/models' | 20 | import { MAccountActor } from '@server/types/models' |
22 | import { AttributesOnly } from '@shared/core-utils' | 21 | import { AttributesOnly } from '@shared/core-utils' |
23 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 22 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
@@ -41,6 +40,7 @@ import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor' | |||
41 | import { ActorFollowModel } from '../actor/actor-follow' | 40 | import { ActorFollowModel } from '../actor/actor-follow' |
42 | import { ActorImageModel } from '../actor/actor-image' | 41 | import { ActorImageModel } from '../actor/actor-image' |
43 | import { ServerModel } from '../server/server' | 42 | import { ServerModel } from '../server/server' |
43 | import { setAsUpdated } from '../shared' | ||
44 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' | 44 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' |
45 | import { VideoModel } from './video' | 45 | import { VideoModel } from './video' |
46 | import { VideoPlaylistModel } from './video-playlist' | 46 | import { VideoPlaylistModel } from './video-playlist' |
@@ -58,6 +58,7 @@ export enum ScopeNames { | |||
58 | type AvailableForListOptions = { | 58 | type AvailableForListOptions = { |
59 | actorId: number | 59 | actorId: number |
60 | search?: string | 60 | search?: string |
61 | host?: string | ||
61 | } | 62 | } |
62 | 63 | ||
63 | type AvailableWithStatsOptions = { | 64 | type AvailableWithStatsOptions = { |
@@ -83,6 +84,33 @@ export type SummaryOptions = { | |||
83 | // Only list local channels OR channels that are on an instance followed by actorId | 84 | // Only list local channels OR channels that are on an instance followed by actorId |
84 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId) | 85 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId) |
85 | 86 | ||
87 | const whereActor = { | ||
88 | [Op.or]: [ | ||
89 | { | ||
90 | serverId: null | ||
91 | }, | ||
92 | { | ||
93 | serverId: { | ||
94 | [Op.in]: Sequelize.literal(inQueryInstanceFollow) | ||
95 | } | ||
96 | } | ||
97 | ] | ||
98 | } | ||
99 | |||
100 | let serverRequired = false | ||
101 | let whereServer: WhereOptions | ||
102 | |||
103 | if (options.host && options.host !== WEBSERVER.HOST) { | ||
104 | serverRequired = true | ||
105 | whereServer = { host: options.host } | ||
106 | } | ||
107 | |||
108 | if (options.host === WEBSERVER.HOST) { | ||
109 | Object.assign(whereActor, { | ||
110 | [Op.and]: [ { serverId: null } ] | ||
111 | }) | ||
112 | } | ||
113 | |||
86 | return { | 114 | return { |
87 | include: [ | 115 | include: [ |
88 | { | 116 | { |
@@ -90,20 +118,19 @@ export type SummaryOptions = { | |||
90 | exclude: unusedActorAttributesForAPI | 118 | exclude: unusedActorAttributesForAPI |
91 | }, | 119 | }, |
92 | model: ActorModel, | 120 | model: ActorModel, |
93 | where: { | 121 | where: whereActor, |
94 | [Op.or]: [ | ||
95 | { | ||
96 | serverId: null | ||
97 | }, | ||
98 | { | ||
99 | serverId: { | ||
100 | [Op.in]: Sequelize.literal(inQueryInstanceFollow) | ||
101 | } | ||
102 | } | ||
103 | ] | ||
104 | }, | ||
105 | include: [ | 122 | include: [ |
106 | { | 123 | { |
124 | model: ServerModel, | ||
125 | required: serverRequired, | ||
126 | where: whereServer | ||
127 | }, | ||
128 | { | ||
129 | model: ActorImageModel, | ||
130 | as: 'Avatar', | ||
131 | required: false | ||
132 | }, | ||
133 | { | ||
107 | model: ActorImageModel, | 134 | model: ActorImageModel, |
108 | as: 'Banner', | 135 | as: 'Banner', |
109 | required: false | 136 | required: false |
@@ -431,6 +458,8 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` | |||
431 | start: number | 458 | start: number |
432 | count: number | 459 | count: number |
433 | sort: string | 460 | sort: string |
461 | |||
462 | host?: string | ||
434 | }) { | 463 | }) { |
435 | const attributesInclude = [] | 464 | const attributesInclude = [] |
436 | const escapedSearch = VideoChannelModel.sequelize.escape(options.search) | 465 | const escapedSearch = VideoChannelModel.sequelize.escape(options.search) |
@@ -458,7 +487,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` | |||
458 | 487 | ||
459 | return VideoChannelModel | 488 | return VideoChannelModel |
460 | .scope({ | 489 | .scope({ |
461 | method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] | 490 | method: [ ScopeNames.FOR_API, { actorId: options.actorId, host: options.host } as AvailableForListOptions ] |
462 | }) | 491 | }) |
463 | .findAndCountAll(query) | 492 | .findAndCountAll(query) |
464 | .then(({ rows, count }) => { | 493 | .then(({ rows, count }) => { |