aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-27 09:04:04 +0100
committerChocobozzz <me@florianbigard.com>2019-12-27 09:04:04 +0100
commit822c7e610d19e3320519a6ae5c90c01db971f03f (patch)
tree7e9afe855cab8b09708e3fe71caf37bc4e8dc19f /server
parent227eb02f9ac100e1314cab4c4751e450bbe14d21 (diff)
downloadPeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.tar.gz
PeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.tar.zst
PeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.zip
Fix playlist search
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-playlist.ts21
-rw-r--r--server/tests/api/videos/video-playlists.ts19
2 files changed, 25 insertions, 15 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index ef87a7ee9..71a580249 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -13,11 +13,10 @@ import {
13 Model, 13 Model,
14 Scopes, 14 Scopes,
15 Table, 15 Table,
16 UpdatedAt, 16 UpdatedAt
17 Sequelize
18} from 'sequelize-typescript' 17} from 'sequelize-typescript'
19import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 18import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
20import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils' 19import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
21import { 20import {
22 isVideoPlaylistDescriptionValid, 21 isVideoPlaylistDescriptionValid,
23 isVideoPlaylistNameValid, 22 isVideoPlaylistNameValid,
@@ -46,7 +45,8 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
46import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' 45import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
47import * as Bluebird from 'bluebird' 46import * as Bluebird from 'bluebird'
48import { 47import {
49 MVideoPlaylistAccountThumbnail, MVideoPlaylistAP, 48 MVideoPlaylistAccountThumbnail,
49 MVideoPlaylistAP,
50 MVideoPlaylistFormattable, 50 MVideoPlaylistFormattable,
51 MVideoPlaylistFull, 51 MVideoPlaylistFull,
52 MVideoPlaylistFullSummary, 52 MVideoPlaylistFullSummary,
@@ -166,18 +166,9 @@ type AvailableForListOptions = {
166 } 166 }
167 167
168 if (options.search) { 168 if (options.search) {
169 const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search)
170 const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%')
171 whereAnd.push({ 169 whereAnd.push({
172 id: { 170 name: {
173 [ Op.in ]: Sequelize.literal( 171 [ Op.iLike ]: '%' + options.search + '%'
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 } 172 }
182 }) 173 })
183 } 174 }
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 424b217fb..9fd48ac7c 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -407,6 +407,25 @@ describe('Test video playlists', function () {
407 expect(data).to.have.lengthOf(1) 407 expect(data).to.have.lengthOf(1)
408 expect(data[ 0 ].displayName).to.equal('playlist 3') 408 expect(data[ 0 ].displayName).to.equal('playlist 3')
409 } 409 }
410
411 {
412 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '3')
413
414 expect(res.body.total).to.equal(1)
415
416 const data: VideoPlaylist[] = res.body.data
417 expect(data).to.have.lengthOf(1)
418 expect(data[ 0 ].displayName).to.equal('playlist 3')
419 }
420
421 {
422 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '4')
423
424 expect(res.body.total).to.equal(0)
425
426 const data: VideoPlaylist[] = res.body.data
427 expect(data).to.have.lengthOf(0)
428 }
410 }) 429 })
411 430
412 it('Should not list unlisted or private playlists', async function () { 431 it('Should not list unlisted or private playlists', async function () {