aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-19 09:10:01 +0200
committerChocobozzz <me@florianbigard.com>2021-10-20 09:25:44 +0200
commit9593a78ae1368a9ad8bb11044fce6fde2892701a (patch)
tree6a048d32cdcfdfc3c1ea6c02c4a86d8861bac1e7 /server/middlewares/validators/shared
parent9c58375c082dc044f683487e81c0a80a10b3a087 (diff)
downloadPeerTube-9593a78ae1368a9ad8bb11044fce6fde2892701a.tar.gz
PeerTube-9593a78ae1368a9ad8bb11044fce6fde2892701a.tar.zst
PeerTube-9593a78ae1368a9ad8bb11044fce6fde2892701a.zip
Refactor sort middlewares
Diffstat (limited to 'server/middlewares/validators/shared')
-rw-r--r--server/middlewares/validators/shared/utils.ts22
1 files changed, 0 insertions, 22 deletions
diff --git a/server/middlewares/validators/shared/utils.ts b/server/middlewares/validators/shared/utils.ts
index 5c66ad500..8e451a24c 100644
--- a/server/middlewares/validators/shared/utils.ts
+++ b/server/middlewares/validators/shared/utils.ts
@@ -22,26 +22,6 @@ function areValidationErrors (req: express.Request, res: express.Response) {
22 return false 22 return false
23} 23}
24 24
25function checkSort (sortableColumns: string[], tags: string[] = []) {
26 return [
27 query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
28
29 (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking sort parameters', { parameters: req.query, tags })
31
32 if (areValidationErrors(req, res)) return
33
34 return next()
35 }
36 ]
37}
38
39function createSortableColumns (sortableColumns: string[]) {
40 const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn)
41
42 return sortableColumns.concat(sortableColumnDesc)
43}
44
45function isValidVideoIdParam (paramName: string) { 25function isValidVideoIdParam (paramName: string) {
46 return param(paramName) 26 return param(paramName)
47 .customSanitizer(toCompleteUUID) 27 .customSanitizer(toCompleteUUID)
@@ -58,8 +38,6 @@ function isValidPlaylistIdParam (paramName: string) {
58 38
59export { 39export {
60 areValidationErrors, 40 areValidationErrors,
61 checkSort,
62 createSortableColumns,
63 isValidVideoIdParam, 41 isValidVideoIdParam,
64 isValidPlaylistIdParam 42 isValidPlaylistIdParam
65} 43}