Fix playlist search
This commit is contained in:
parent
227eb02f9a
commit
822c7e610d
|
@ -13,11 +13,10 @@ import {
|
||||||
Model,
|
Model,
|
||||||
Scopes,
|
Scopes,
|
||||||
Table,
|
Table,
|
||||||
UpdatedAt,
|
UpdatedAt
|
||||||
Sequelize
|
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
||||||
import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils'
|
import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
|
||||||
import {
|
import {
|
||||||
isVideoPlaylistDescriptionValid,
|
isVideoPlaylistDescriptionValid,
|
||||||
isVideoPlaylistNameValid,
|
isVideoPlaylistNameValid,
|
||||||
|
@ -46,7 +45,8 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
|
||||||
import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
|
import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import {
|
import {
|
||||||
MVideoPlaylistAccountThumbnail, MVideoPlaylistAP,
|
MVideoPlaylistAccountThumbnail,
|
||||||
|
MVideoPlaylistAP,
|
||||||
MVideoPlaylistFormattable,
|
MVideoPlaylistFormattable,
|
||||||
MVideoPlaylistFull,
|
MVideoPlaylistFull,
|
||||||
MVideoPlaylistFullSummary,
|
MVideoPlaylistFullSummary,
|
||||||
|
@ -166,18 +166,9 @@ type AvailableForListOptions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.search) {
|
if (options.search) {
|
||||||
const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search)
|
|
||||||
const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%')
|
|
||||||
whereAnd.push({
|
whereAnd.push({
|
||||||
id: {
|
name: {
|
||||||
[ Op.in ]: Sequelize.literal(
|
[ Op.iLike ]: '%' + options.search + '%'
|
||||||
'(' +
|
|
||||||
'SELECT "videoPlaylist"."id" FROM "videoPlaylist" ' +
|
|
||||||
'WHERE ' +
|
|
||||||
'lower(immutable_unaccent("videoPlaylist"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
|
|
||||||
'lower(immutable_unaccent("videoPlaylist"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
|
|
||||||
')'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,6 +407,25 @@ describe('Test video playlists', function () {
|
||||||
expect(data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
expect(data[ 0 ].displayName).to.equal('playlist 3')
|
expect(data[ 0 ].displayName).to.equal('playlist 3')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '3')
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(1)
|
||||||
|
|
||||||
|
const data: VideoPlaylist[] = res.body.data
|
||||||
|
expect(data).to.have.lengthOf(1)
|
||||||
|
expect(data[ 0 ].displayName).to.equal('playlist 3')
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '4')
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(0)
|
||||||
|
|
||||||
|
const data: VideoPlaylist[] = res.body.data
|
||||||
|
expect(data).to.have.lengthOf(0)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not list unlisted or private playlists', async function () {
|
it('Should not list unlisted or private playlists', async function () {
|
||||||
|
|
|
@ -45,13 +45,14 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string) {
|
function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string, search?: string) {
|
||||||
const path = '/api/v1/accounts/' + accountName + '/video-playlists'
|
const path = '/api/v1/accounts/' + accountName + '/video-playlists'
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
start,
|
start,
|
||||||
count,
|
count,
|
||||||
sort
|
sort,
|
||||||
|
search
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeGetRequest({
|
return makeGetRequest({
|
||||||
|
|
Loading…
Reference in New Issue