1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add ability to sort by originallyPublishedAt

This commit is contained in:
Chocobozzz 2020-04-20 14:05:52 +02:00
parent 1f41ca6566
commit 2fd59d7d89
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 50 additions and 9 deletions

View file

@ -321,6 +321,10 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
if (options.isCount !== true) {
if (exists(options.sort)) {
if (options.sort === '-originallyPublishedAt' || options.sort === 'originallyPublishedAt') {
attributes.push('COALESCE("video"."originallyPublishedAt", "video"."publishedAt") AS "publishedAtForOrder"')
}
order = buildOrder(model, options.sort)
suffix += `${order} `
}
@ -365,6 +369,8 @@ function buildOrder (model: typeof Model, value: string) {
if (field.toLowerCase() === 'match') { // Search
firstSort = '"similarity"'
} else if (field === 'originallyPublishedAt') {
firstSort = '"publishedAtForOrder"'
} else if (field.includes('.')) {
firstSort = field
} else {