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' ], USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
VIDEO_PLAYLISTS: [ 'name', 'createdAt', 'updatedAt' ], VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
PLUGINS: [ 'name', '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 { Model, Sequelize } from 'sequelize-typescript'
import validator from 'validator'
import { Col } from 'sequelize/types/lib/utils' import { Col } from 'sequelize/types/lib/utils'
import { literal, OrderItem, Op } from 'sequelize' import validator from 'validator'
type SortType = { sortModel: string, sortValue: string } type SortType = { sortModel: string, sortValue: string }
@ -22,6 +22,16 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
return [ [ finalField, direction ], lastSort ] 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[] { function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildDirectionAndField(value) const { direction, field } = buildDirectionAndField(value)
@ -227,6 +237,7 @@ export {
buildBlockedAccountSQL, buildBlockedAccountSQL,
buildBlockedAccountSQLOptimized, buildBlockedAccountSQLOptimized,
buildLocalActorIdsIn, buildLocalActorIdsIn,
getPlaylistSort,
SortType, SortType,
buildLocalAccountIdsIn, buildLocalAccountIdsIn,
getSort, getSort,

View File

@ -16,7 +16,7 @@ import {
UpdatedAt UpdatedAt
} 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 } from '../utils' import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getPlaylistSort, getPlaylistSort, isOutdated, throwIfNotValid } from '../utils'
import { import {
isVideoPlaylistDescriptionValid, isVideoPlaylistDescriptionValid,
isVideoPlaylistNameValid, isVideoPlaylistNameValid,
@ -312,7 +312,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
const query = { const query = {
offset: options.start, offset: options.start,
limit: options.count, limit: options.count,
order: getSort(options.sort) order: getPlaylistSort(options.sort)
} }
const scopes: (string | ScopeOptions)[] = [ const scopes: (string | ScopeOptions)[] = [