diff options
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r-- | server/models/video/video-channel.ts | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index f3401fb9c..9da965bbc 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -315,9 +315,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
315 | start: number | 315 | start: number |
316 | count: number | 316 | count: number |
317 | sort: string | 317 | sort: string |
318 | search?: string | ||
319 | }) { | 318 | }) { |
320 | const { actorId, search } = parameters | 319 | const { actorId } = parameters |
321 | 320 | ||
322 | const query = { | 321 | const query = { |
323 | offset: parameters.start, | 322 | offset: parameters.start, |
@@ -326,7 +325,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
326 | } | 325 | } |
327 | 326 | ||
328 | const scopes = { | 327 | const scopes = { |
329 | method: [ ScopeNames.FOR_API, { actorId, search } as AvailableForListOptions ] | 328 | method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] |
330 | } | 329 | } |
331 | return VideoChannelModel | 330 | return VideoChannelModel |
332 | .scope(scopes) | 331 | .scope(scopes) |
@@ -405,7 +404,23 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
405 | count: number | 404 | count: number |
406 | sort: string | 405 | sort: string |
407 | withStats?: boolean | 406 | withStats?: boolean |
407 | search?: string | ||
408 | }) { | 408 | }) { |
409 | const escapedSearch = VideoModel.sequelize.escape(options.search) | ||
410 | const escapedLikeSearch = VideoModel.sequelize.escape('%' + options.search + '%') | ||
411 | const where = options.search | ||
412 | ? { | ||
413 | [Op.or]: [ | ||
414 | Sequelize.literal( | ||
415 | 'lower(immutable_unaccent("VideoChannelModel"."name")) % lower(immutable_unaccent(' + escapedSearch + '))' | ||
416 | ), | ||
417 | Sequelize.literal( | ||
418 | 'lower(immutable_unaccent("VideoChannelModel"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' | ||
419 | ) | ||
420 | ] | ||
421 | } | ||
422 | : null | ||
423 | |||
409 | const query = { | 424 | const query = { |
410 | offset: options.start, | 425 | offset: options.start, |
411 | limit: options.count, | 426 | limit: options.count, |
@@ -418,7 +433,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
418 | }, | 433 | }, |
419 | required: true | 434 | required: true |
420 | } | 435 | } |
421 | ] | 436 | ], |
437 | where | ||
422 | } | 438 | } |
423 | 439 | ||
424 | const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] | 440 | const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] |