aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-01 15:08:59 +0100
committerChocobozzz <me@florianbigard.com>2020-12-01 15:08:59 +0100
commit49cff3a4c950b22ae13f345dc4eab803d96a236e (patch)
treecd918676792834b6cfaee70c582249496320ddd1
parent15feebd97ab5291f81b2a8cdcb16a8e4f4c5aa69 (diff)
downloadPeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.tar.gz
PeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.tar.zst
PeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.zip
Keep displayName as valid playlist sort
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/models/utils.ts15
-rw-r--r--server/models/video/video-playlist.ts4
3 files changed, 16 insertions, 5 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 4bba68a81..2c7acd757 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -85,7 +85,7 @@ const SORTABLE_COLUMNS = {
85 85
86 USER_NOTIFICATIONS: [ 'createdAt', 'read' ], 86 USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
87 87
88 VIDEO_PLAYLISTS: [ 'name', 'createdAt', 'updatedAt' ], 88 VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
89 89
90 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ], 90 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],
91 91
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 @@
1import { literal, Op, OrderItem } from 'sequelize'
1import { Model, Sequelize } from 'sequelize-typescript' 2import { Model, Sequelize } from 'sequelize-typescript'
2import validator from 'validator'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { literal, OrderItem, Op } from 'sequelize' 4import validator from 'validator'
5 5
6type SortType = { sortModel: string, sortValue: string } 6type SortType = { sortModel: string, sortValue: string }
7 7
@@ -22,6 +22,16 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
22 return [ [ finalField, direction ], lastSort ] 22 return [ [ finalField, direction ], lastSort ]
23} 23}
24 24
25function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
26 const { direction, field } = buildDirectionAndField(value)
27
28 if (field.toLowerCase() === 'name') {
29 return [ [ 'displayName', direction ], lastSort ]
30 }
31
32 return getSort(value, lastSort)
33}
34
25function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { 35function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
26 const { direction, field } = buildDirectionAndField(value) 36 const { direction, field } = buildDirectionAndField(value)
27 37
@@ -227,6 +237,7 @@ export {
227 buildBlockedAccountSQL, 237 buildBlockedAccountSQL,
228 buildBlockedAccountSQLOptimized, 238 buildBlockedAccountSQLOptimized,
229 buildLocalActorIdsIn, 239 buildLocalActorIdsIn,
240 getPlaylistSort,
230 SortType, 241 SortType,
231 buildLocalAccountIdsIn, 242 buildLocalAccountIdsIn,
232 getSort, 243 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 {
16 UpdatedAt 16 UpdatedAt
17} from 'sequelize-typescript' 17} from 'sequelize-typescript'
18import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 18import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
19import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' 19import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getPlaylistSort, getPlaylistSort, isOutdated, throwIfNotValid } from '../utils'
20import { 20import {
21 isVideoPlaylistDescriptionValid, 21 isVideoPlaylistDescriptionValid,
22 isVideoPlaylistNameValid, 22 isVideoPlaylistNameValid,
@@ -312,7 +312,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
312 const query = { 312 const query = {
313 offset: options.start, 313 offset: options.start,
314 limit: options.count, 314 limit: options.count,
315 order: getSort(options.sort) 315 order: getPlaylistSort(options.sort)
316 } 316 }
317 317
318 const scopes: (string | ScopeOptions)[] = [ 318 const scopes: (string | ScopeOptions)[] = [