]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
parseQueryStringFilter cleanup
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index 8f0a814dece605d923ea44fd6efd7c7f309e9cfb..455f9f30ff032c158404535196db985de1e0e36d 100644 (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 {