]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix sitemap endpoint
authorChocobozzz <me@florianbigard.com>
Wed, 11 Mar 2020 07:40:13 +0000 (08:40 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 11 Mar 2020 14:02:20 +0000 (15:02 +0100)
server/models/video/video-query-builder.ts

index 61f628c0683d4ed64ac3c6c4be2ce003a445bba3..655abf19871f7e23991e59fc5f5feac6a1a80bf5 100644 (file)
@@ -3,6 +3,7 @@ import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
 import { Model } from 'sequelize-typescript'
 import { MUserAccountId, MUserId } from '@server/typings/models'
 import validator from 'validator'
+import { exists } from '@server/helpers/custom-validators/misc'
 
 export type BuildVideosQueryOptions = {
   attributes?: string[]
@@ -312,14 +313,21 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
   let suffix = ''
   let order = ''
   if (options.isCount !== true) {
-    const count = parseInt(options.count + '', 10)
-    const start = parseInt(options.start + '', 10)
 
-    order = buildOrder(model, options.sort)
+    if (exists(options.sort)) {
+      order = buildOrder(model, options.sort)
+      suffix += `${order} `
+    }
+
+    if (exists(options.count)) {
+      const count = parseInt(options.count + '', 10)
+      suffix += `LIMIT ${count} `
+    }
 
-    suffix = order + ' ' +
-      'LIMIT ' + count + ' ' +
-      'OFFSET ' + start
+    if (exists(options.start)) {
+      const start = parseInt(options.start + '', 10)
+      suffix += `OFFSET ${start} `
+    }
   }
 
   const cteString = cte.length !== 0