aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-playlist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-28 10:32:40 +0200
committerChocobozzz <me@florianbigard.com>2021-07-28 10:32:40 +0200
commitfa47956ecf51a6d5d10aeb25d2e4db3da90c7d58 (patch)
treebd626648077f84fb4628af3a37acf260597fa0ef /server/models/video/video-playlist.ts
parentf68d1cb6ac4aa4fb563b9eeb831fccffee260b2f (diff)
downloadPeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.tar.gz
PeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.tar.zst
PeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.zip
Filter host for channels and playlists search
Diffstat (limited to 'server/models/video/video-playlist.ts')
-rw-r--r--server/models/video/video-playlist.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 72ba474b4..a2dc7075d 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -17,7 +17,6 @@ import {
17 Table, 17 Table,
18 UpdatedAt 18 UpdatedAt
19} from 'sequelize-typescript' 19} from 'sequelize-typescript'
20import { setAsUpdated } from '@server/helpers/database-utils'
21import { buildUUID, uuidToShort } from '@server/helpers/uuid' 20import { buildUUID, uuidToShort } from '@server/helpers/uuid'
22import { MAccountId, MChannelId } from '@server/types/models' 21import { MAccountId, MChannelId } from '@server/types/models'
23import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils' 22import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils'
@@ -53,6 +52,7 @@ import {
53} from '../../types/models/video/video-playlist' 52} from '../../types/models/video/video-playlist'
54import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' 53import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account'
55import { ActorModel } from '../actor/actor' 54import { ActorModel } from '../actor/actor'
55import { setAsUpdated } from '../shared'
56import { 56import {
57 buildServerIdsFollowedBy, 57 buildServerIdsFollowedBy,
58 buildTrigramSearchIndex, 58 buildTrigramSearchIndex,
@@ -82,6 +82,7 @@ type AvailableForListOptions = {
82 videoChannelId?: number 82 videoChannelId?: number
83 listMyPlaylists?: boolean 83 listMyPlaylists?: boolean
84 search?: string 84 search?: string
85 host?: string
85 withVideos?: boolean 86 withVideos?: boolean
86} 87}
87 88
@@ -141,9 +142,19 @@ function getVideoLengthSelect () {
141 ] 142 ]
142 }, 143 },
143 [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { 144 [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => {
145 const whereAnd: WhereOptions[] = []
146
147 const whereServer = options.host && options.host !== WEBSERVER.HOST
148 ? { host: options.host }
149 : undefined
150
144 let whereActor: WhereOptions = {} 151 let whereActor: WhereOptions = {}
145 152
146 const whereAnd: WhereOptions[] = [] 153 if (options.host === WEBSERVER.HOST) {
154 whereActor = {
155 [Op.and]: [ { serverId: null } ]
156 }
157 }
147 158
148 if (options.listMyPlaylists !== true) { 159 if (options.listMyPlaylists !== true) {
149 whereAnd.push({ 160 whereAnd.push({
@@ -168,9 +179,7 @@ function getVideoLengthSelect () {
168 }) 179 })
169 } 180 }
170 181
171 whereActor = { 182 Object.assign(whereActor, { [Op.or]: whereActorOr })
172 [Op.or]: whereActorOr
173 }
174 } 183 }
175 184
176 if (options.accountId) { 185 if (options.accountId) {
@@ -228,7 +237,7 @@ function getVideoLengthSelect () {
228 include: [ 237 include: [
229 { 238 {
230 model: AccountModel.scope({ 239 model: AccountModel.scope({
231 method: [ AccountScopeNames.SUMMARY, { whereActor } as SummaryOptions ] 240 method: [ AccountScopeNames.SUMMARY, { whereActor, whereServer } as SummaryOptions ]
232 }), 241 }),
233 required: true 242 required: true
234 }, 243 },
@@ -349,6 +358,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
349 videoChannelId?: number 358 videoChannelId?: number
350 listMyPlaylists?: boolean 359 listMyPlaylists?: boolean
351 search?: string 360 search?: string
361 host?: string
352 withVideos?: boolean // false by default 362 withVideos?: boolean // false by default
353 }) { 363 }) {
354 const query = { 364 const query = {
@@ -368,6 +378,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
368 videoChannelId: options.videoChannelId, 378 videoChannelId: options.videoChannelId,
369 listMyPlaylists: options.listMyPlaylists, 379 listMyPlaylists: options.listMyPlaylists,
370 search: options.search, 380 search: options.search,
381 host: options.host,
371 withVideos: options.withVideos || false 382 withVideos: options.withVideos || false
372 } as AvailableForListOptions 383 } as AvailableForListOptions
373 ] 384 ]
@@ -390,6 +401,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
390 count: number 401 count: number
391 sort: string 402 sort: string
392 search?: string 403 search?: string
404 host?: string
393 }) { 405 }) {
394 return VideoPlaylistModel.listForApi({ 406 return VideoPlaylistModel.listForApi({
395 ...options, 407 ...options,