1
0
Fork 0

Keep displayName as valid playlist sort

This commit is contained in:
Chocobozzz 2020-12-01 15:08:59 +01:00
parent 15feebd97a
commit 49cff3a4c9
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 16 additions and 5 deletions

View file

@ -85,7 +85,7 @@ const SORTABLE_COLUMNS = {
USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
VIDEO_PLAYLISTS: [ 'name', 'createdAt', 'updatedAt' ],
VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],

View file

@ -1,7 +1,7 @@
import { literal, Op, OrderItem } from 'sequelize'
import { Model, Sequelize } from 'sequelize-typescript'
import validator from 'validator'
import { Col } from 'sequelize/types/lib/utils'
import { literal, OrderItem, Op } from 'sequelize'
import validator from 'validator'
type SortType = { sortModel: string, sortValue: string }
@ -22,6 +22,16 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
return [ [ finalField, direction ], lastSort ]
}
function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildDirectionAndField(value)
if (field.toLowerCase() === 'name') {
return [ [ 'displayName', direction ], lastSort ]
}
return getSort(value, lastSort)
}
function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildDirectionAndField(value)
@ -227,6 +237,7 @@ export {
buildBlockedAccountSQL,
buildBlockedAccountSQLOptimized,
buildLocalActorIdsIn,
getPlaylistSort,
SortType,
buildLocalAccountIdsIn,
getSort,

View file

@ -16,7 +16,7 @@ import {
UpdatedAt
} from 'sequelize-typescript'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getPlaylistSort, getPlaylistSort, isOutdated, throwIfNotValid } from '../utils'
import {
isVideoPlaylistDescriptionValid,
isVideoPlaylistNameValid,
@ -312,7 +312,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
const query = {
offset: options.start,
limit: options.count,
order: getSort(options.sort)
order: getPlaylistSort(options.sort)
}
const scopes: (string | ScopeOptions)[] = [