From 2fd59d7d89d1c389446ee67838c821e2622fc8ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 20 Apr 2020 14:05:52 +0200 Subject: Add ability to sort by originallyPublishedAt --- server/models/video/video-query-builder.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'server/models') diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 8f0a814de..455f9f30f 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts @@ -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 { -- cgit v1.2.3