]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/sort.ts
Fix transcoding
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
... / ...
CommitLineData
1import * as express from 'express'
2import { SortType } from '../models/utils'
3
4const setDefaultSort = setDefaultSortFactory('-createdAt')
5
6const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
7
8const setDefaultSearchSort = setDefaultSortFactory('-match')
9
10function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
11 let newSort: SortType = { sortModel: undefined, sortValue: '' }
12
13 if (!req.query.sort) req.query.sort = '-createdAt'
14
15 // Set model we want to sort onto
16 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
17 req.query.sort === '-id' || req.query.sort === 'id') {
18 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
19 newSort.sortModel = undefined
20 } else {
21 newSort.sortModel = 'Video'
22 }
23
24 newSort.sortValue = req.query.sort
25
26 req.query.sort = newSort
27
28 return next()
29}
30
31// ---------------------------------------------------------------------------
32
33export {
34 setDefaultSort,
35 setDefaultSearchSort,
36 setDefaultVideoRedundanciesSort,
37 setBlacklistSort
38}
39
40// ---------------------------------------------------------------------------
41
42function setDefaultSortFactory (sort: string) {
43 return (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 if (!req.query.sort) req.query.sort = sort
45
46 return next()
47 }
48}