diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-28 16:40:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-28 16:40:21 +0200 |
commit | fbd67e7f386504e50f2504cb6386700a58906f16 (patch) | |
tree | 1a7143aaea76ce4e195fb9d6214a0cd769c556ea /server/models/video/video-playlist.ts | |
parent | 164c8d46cf5c948a28b4ac0e596fad9b83b2c229 (diff) | |
download | PeerTube-fbd67e7f386504e50f2504cb6386700a58906f16.tar.gz PeerTube-fbd67e7f386504e50f2504cb6386700a58906f16.tar.zst PeerTube-fbd67e7f386504e50f2504cb6386700a58906f16.zip |
Add ability to search by uuids/actor names
Diffstat (limited to 'server/models/video/video-playlist.ts')
-rw-r--r-- | server/models/video/video-playlist.ts | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index a2dc7075d..caa79952d 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -83,6 +83,7 @@ type AvailableForListOptions = { | |||
83 | listMyPlaylists?: boolean | 83 | listMyPlaylists?: boolean |
84 | search?: string | 84 | search?: string |
85 | host?: string | 85 | host?: string |
86 | uuids?: string[] | ||
86 | withVideos?: boolean | 87 | withVideos?: boolean |
87 | } | 88 | } |
88 | 89 | ||
@@ -200,18 +201,26 @@ function getVideoLengthSelect () { | |||
200 | }) | 201 | }) |
201 | } | 202 | } |
202 | 203 | ||
204 | if (options.uuids) { | ||
205 | whereAnd.push({ | ||
206 | uuid: { | ||
207 | [Op.in]: options.uuids | ||
208 | } | ||
209 | }) | ||
210 | } | ||
211 | |||
203 | if (options.withVideos === true) { | 212 | if (options.withVideos === true) { |
204 | whereAnd.push( | 213 | whereAnd.push( |
205 | literal(`(${getVideoLengthSelect()}) != 0`) | 214 | literal(`(${getVideoLengthSelect()}) != 0`) |
206 | ) | 215 | ) |
207 | } | 216 | } |
208 | 217 | ||
209 | const attributesInclude = [] | 218 | let attributesInclude: any[] = [ literal('0 as similarity') ] |
210 | 219 | ||
211 | if (options.search) { | 220 | if (options.search) { |
212 | const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search) | 221 | const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search) |
213 | const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%') | 222 | const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%') |
214 | attributesInclude.push(createSimilarityAttribute('VideoPlaylistModel.name', options.search)) | 223 | attributesInclude = [ createSimilarityAttribute('VideoPlaylistModel.name', options.search) ] |
215 | 224 | ||
216 | whereAnd.push({ | 225 | whereAnd.push({ |
217 | [Op.or]: [ | 226 | [Op.or]: [ |
@@ -359,6 +368,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
359 | listMyPlaylists?: boolean | 368 | listMyPlaylists?: boolean |
360 | search?: string | 369 | search?: string |
361 | host?: string | 370 | host?: string |
371 | uuids?: string[] | ||
362 | withVideos?: boolean // false by default | 372 | withVideos?: boolean // false by default |
363 | }) { | 373 | }) { |
364 | const query = { | 374 | const query = { |
@@ -379,6 +389,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
379 | listMyPlaylists: options.listMyPlaylists, | 389 | listMyPlaylists: options.listMyPlaylists, |
380 | search: options.search, | 390 | search: options.search, |
381 | host: options.host, | 391 | host: options.host, |
392 | uuids: options.uuids, | ||
382 | withVideos: options.withVideos || false | 393 | withVideos: options.withVideos || false |
383 | } as AvailableForListOptions | 394 | } as AvailableForListOptions |
384 | ] | 395 | ] |
@@ -402,6 +413,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
402 | sort: string | 413 | sort: string |
403 | search?: string | 414 | search?: string |
404 | host?: string | 415 | host?: string |
416 | uuids?: string[] | ||
405 | }) { | 417 | }) { |
406 | return VideoPlaylistModel.listForApi({ | 418 | return VideoPlaylistModel.listForApi({ |
407 | ...options, | 419 | ...options, |