diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-playlist.ts | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 278d80ac0..ef87a7ee9 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -13,10 +13,11 @@ import { | |||
13 | Model, | 13 | Model, |
14 | Scopes, | 14 | Scopes, |
15 | Table, | 15 | Table, |
16 | UpdatedAt | 16 | UpdatedAt, |
17 | Sequelize | ||
17 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
18 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 19 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
19 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' | 20 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils' |
20 | import { | 21 | import { |
21 | isVideoPlaylistDescriptionValid, | 22 | isVideoPlaylistDescriptionValid, |
22 | isVideoPlaylistNameValid, | 23 | isVideoPlaylistNameValid, |
@@ -67,7 +68,8 @@ type AvailableForListOptions = { | |||
67 | type?: VideoPlaylistType | 68 | type?: VideoPlaylistType |
68 | accountId?: number | 69 | accountId?: number |
69 | videoChannelId?: number | 70 | videoChannelId?: number |
70 | privateAndUnlisted?: boolean | 71 | privateAndUnlisted?: boolean, |
72 | search?: string | ||
71 | } | 73 | } |
72 | 74 | ||
73 | @Scopes(() => ({ | 75 | @Scopes(() => ({ |
@@ -163,6 +165,23 @@ type AvailableForListOptions = { | |||
163 | }) | 165 | }) |
164 | } | 166 | } |
165 | 167 | ||
168 | if (options.search) { | ||
169 | const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search) | ||
170 | const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%') | ||
171 | whereAnd.push({ | ||
172 | id: { | ||
173 | [ Op.in ]: Sequelize.literal( | ||
174 | '(' + | ||
175 | 'SELECT "videoPlaylist"."id" FROM "videoPlaylist" ' + | ||
176 | 'WHERE ' + | ||
177 | 'lower(immutable_unaccent("videoPlaylist"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' + | ||
178 | 'lower(immutable_unaccent("videoPlaylist"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' + | ||
179 | ')' | ||
180 | ) | ||
181 | } | ||
182 | }) | ||
183 | } | ||
184 | |||
166 | const where = { | 185 | const where = { |
167 | [Op.and]: whereAnd | 186 | [Op.and]: whereAnd |
168 | } | 187 | } |
@@ -291,7 +310,8 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
291 | type?: VideoPlaylistType, | 310 | type?: VideoPlaylistType, |
292 | accountId?: number, | 311 | accountId?: number, |
293 | videoChannelId?: number, | 312 | videoChannelId?: number, |
294 | privateAndUnlisted?: boolean | 313 | privateAndUnlisted?: boolean, |
314 | search?: string | ||
295 | }) { | 315 | }) { |
296 | const query = { | 316 | const query = { |
297 | offset: options.start, | 317 | offset: options.start, |
@@ -308,7 +328,8 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
308 | followerActorId: options.followerActorId, | 328 | followerActorId: options.followerActorId, |
309 | accountId: options.accountId, | 329 | accountId: options.accountId, |
310 | videoChannelId: options.videoChannelId, | 330 | videoChannelId: options.videoChannelId, |
311 | privateAndUnlisted: options.privateAndUnlisted | 331 | privateAndUnlisted: options.privateAndUnlisted, |
332 | search: options.search | ||
312 | } as AvailableForListOptions | 333 | } as AvailableForListOptions |
313 | ] | 334 | ] |
314 | }, | 335 | }, |