diff options
author | Chocobozzz <me@florianbigard.com> | 2020-03-11 08:40:13 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-03-11 15:02:20 +0100 |
commit | fab6746354f9d9cb65c35d8bd9352c4b773b4c69 (patch) | |
tree | c4465558a82821cd373cb1f23d0bb9e8d158ed68 | |
parent | cd7ec86f5c621f3ad01753e81fc67358db6e7df6 (diff) | |
download | PeerTube-fab6746354f9d9cb65c35d8bd9352c4b773b4c69.tar.gz PeerTube-fab6746354f9d9cb65c35d8bd9352c4b773b4c69.tar.zst PeerTube-fab6746354f9d9cb65c35d8bd9352c4b773b4c69.zip |
Fix sitemap endpoint
-rw-r--r-- | server/models/video/video-query-builder.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 61f628c06..655abf198 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts | |||
@@ -3,6 +3,7 @@ import { buildDirectionAndField, createSafeIn } from '@server/models/utils' | |||
3 | import { Model } from 'sequelize-typescript' | 3 | import { Model } from 'sequelize-typescript' |
4 | import { MUserAccountId, MUserId } from '@server/typings/models' | 4 | import { MUserAccountId, MUserId } from '@server/typings/models' |
5 | import validator from 'validator' | 5 | import validator from 'validator' |
6 | import { exists } from '@server/helpers/custom-validators/misc' | ||
6 | 7 | ||
7 | export type BuildVideosQueryOptions = { | 8 | export type BuildVideosQueryOptions = { |
8 | attributes?: string[] | 9 | attributes?: string[] |
@@ -312,14 +313,21 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) | |||
312 | let suffix = '' | 313 | let suffix = '' |
313 | let order = '' | 314 | let order = '' |
314 | if (options.isCount !== true) { | 315 | if (options.isCount !== true) { |
315 | const count = parseInt(options.count + '', 10) | ||
316 | const start = parseInt(options.start + '', 10) | ||
317 | 316 | ||
318 | order = buildOrder(model, options.sort) | 317 | if (exists(options.sort)) { |
318 | order = buildOrder(model, options.sort) | ||
319 | suffix += `${order} ` | ||
320 | } | ||
321 | |||
322 | if (exists(options.count)) { | ||
323 | const count = parseInt(options.count + '', 10) | ||
324 | suffix += `LIMIT ${count} ` | ||
325 | } | ||
319 | 326 | ||
320 | suffix = order + ' ' + | 327 | if (exists(options.start)) { |
321 | 'LIMIT ' + count + ' ' + | 328 | const start = parseInt(options.start + '', 10) |
322 | 'OFFSET ' + start | 329 | suffix += `OFFSET ${start} ` |
330 | } | ||
323 | } | 331 | } |
324 | 332 | ||
325 | const cteString = cte.length !== 0 | 333 | const cteString = cte.length !== 0 |