]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/sort.ts
Add ability to forbid user to upload video
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
1 import 'express-validator'
2 import * as express from 'express'
3
4 import { SortType } from '../helpers'
5 import { database } from '../initializers'
6
7 function setPodsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
8 if (!req.query.sort) req.query.sort = '-createdAt'
9
10 return next()
11 }
12
13 function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
14 if (!req.query.sort) req.query.sort = '-createdAt'
15
16 return next()
17 }
18
19 function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
20 if (!req.query.sort) req.query.sort = '-createdAt'
21
22 return next()
23 }
24
25 function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
26 if (!req.query.sort) req.query.sort = '-createdAt'
27
28 return next()
29 }
30
31 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
32 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
33
34 if (!req.query.sort) req.query.sort = '-createdAt'
35
36 // Set model we want to sort onto
37 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
38 req.query.sort === '-id' || req.query.sort === 'id') {
39 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
40 newSort.sortModel = undefined
41 } else {
42 newSort.sortModel = database.Video
43 }
44
45 newSort.sortValue = req.query.sort
46
47 req.query.sort = newSort
48
49 return next()
50 }
51
52 // ---------------------------------------------------------------------------
53
54 export {
55 setPodsSort,
56 setUsersSort,
57 setVideoAbusesSort,
58 setVideosSort,
59 setBlacklistSort
60 }