]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/sort.ts
Fix typo in error log
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
CommitLineData
69818c93 1import * as express from 'express'
06215f15 2import { SortType } from '../models/utils'
792dbaf0 3
1174a847 4function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
7a7724e6
C
5 if (!req.query.sort) req.query.sort = '-createdAt'
6
7 return next()
8}
9
57c36b27 10function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) {
d525fc39 11 if (!req.query.sort) req.query.sort = '-match'
57c36b27
C
12
13 return next()
14}
15
792dbaf0 16function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
c1e791ba 17 let newSort: SortType = { sortModel: undefined, sortValue: '' }
792dbaf0
GS
18
19 if (!req.query.sort) req.query.sort = '-createdAt'
20
21 // Set model we want to sort onto
22 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
23 req.query.sort === '-id' || req.query.sort === 'id') {
24 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
25 newSort.sortModel = undefined
26 } else {
3fd3ab2d 27 newSort.sortModel = 'Video'
792dbaf0
GS
28 }
29
30 newSort.sortValue = req.query.sort
31
32 req.query.sort = newSort
33
34 return next()
35}
36
a877d5ac
C
37// ---------------------------------------------------------------------------
38
65fcc311 39export {
1174a847 40 setDefaultSort,
57c36b27 41 setDefaultSearchSort,
1174a847 42 setBlacklistSort
65fcc311 43}