diff options
author | Chocobozzz <me@florianbigard.com> | 2019-12-27 09:04:04 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-12-27 09:04:04 +0100 |
commit | 822c7e610d19e3320519a6ae5c90c01db971f03f (patch) | |
tree | 7e9afe855cab8b09708e3fe71caf37bc4e8dc19f | |
parent | 227eb02f9ac100e1314cab4c4751e450bbe14d21 (diff) | |
download | PeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.tar.gz PeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.tar.zst PeerTube-822c7e610d19e3320519a6ae5c90c01db971f03f.zip |
Fix playlist search
-rw-r--r-- | server/models/video/video-playlist.ts | 21 | ||||
-rw-r--r-- | server/tests/api/videos/video-playlists.ts | 19 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-playlists.ts | 5 |
3 files changed, 28 insertions, 17 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' |
19 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 18 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
20 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils' | 19 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' |
21 | import { | 20 | import { |
22 | isVideoPlaylistDescriptionValid, | 21 | isVideoPlaylistDescriptionValid, |
23 | isVideoPlaylistNameValid, | 22 | isVideoPlaylistNameValid, |
@@ -46,7 +45,8 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | |||
46 | import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' | 45 | import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' |
47 | import * as Bluebird from 'bluebird' | 46 | import * as Bluebird from 'bluebird' |
48 | import { | 47 | import { |
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 () { |
diff --git a/shared/extra-utils/videos/video-playlists.ts b/shared/extra-utils/videos/video-playlists.ts index cbb073fbc..6762c5973 100644 --- a/shared/extra-utils/videos/video-playlists.ts +++ b/shared/extra-utils/videos/video-playlists.ts | |||
@@ -45,13 +45,14 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st | |||
45 | }) | 45 | }) |
46 | } | 46 | } |
47 | 47 | ||
48 | function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string) { | 48 | function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string, search?: string) { |
49 | const path = '/api/v1/accounts/' + accountName + '/video-playlists' | 49 | const path = '/api/v1/accounts/' + accountName + '/video-playlists' |
50 | 50 | ||
51 | const query = { | 51 | const query = { |
52 | start, | 52 | start, |
53 | count, | 53 | count, |
54 | sort | 54 | sort, |
55 | search | ||
55 | } | 56 | } |
56 | 57 | ||
57 | return makeGetRequest({ | 58 | return makeGetRequest({ |