From 49cff3a4c950b22ae13f345dc4eab803d96a236e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 1 Dec 2020 15:08:59 +0100 Subject: Keep displayName as valid playlist sort --- server/models/utils.ts | 15 +++++++++++++-- server/models/video/video-playlist.ts | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'server/models') diff --git a/server/models/utils.ts b/server/models/utils.ts index 6e5522346..a06d57831 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -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, diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 581179640..b020bfa45 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -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 { const query = { offset: options.start, limit: options.count, - order: getSort(options.sort) + order: getPlaylistSort(options.sort) } const scopes: (string | ScopeOptions)[] = [ -- cgit v1.2.3