aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/admin.ts5
-rw-r--r--server/middlewares/index.ts16
-rw-r--r--server/middlewares/oauth.ts6
-rw-r--r--server/middlewares/pagination.ts5
-rw-r--r--server/middlewares/pods.ts9
-rw-r--r--server/middlewares/search.ts5
-rw-r--r--server/middlewares/secure.ts5
-rw-r--r--server/middlewares/sort.ts9
-rw-r--r--server/middlewares/validators/pagination.ts5
-rw-r--r--server/middlewares/validators/pods.ts7
-rw-r--r--server/middlewares/validators/remote/signature.ts5
-rw-r--r--server/middlewares/validators/remote/videos.ts9
-rw-r--r--server/middlewares/validators/sort.ts13
-rw-r--r--server/middlewares/validators/users.ts11
-rw-r--r--server/middlewares/validators/utils.ts5
-rw-r--r--server/middlewares/validators/videos.ts28
16 files changed, 93 insertions, 50 deletions
diff --git a/server/middlewares/admin.ts b/server/middlewares/admin.ts
index 28b6a9a12..812397352 100644
--- a/server/middlewares/admin.ts
+++ b/server/middlewares/admin.ts
@@ -1,6 +1,9 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { logger } from '../helpers' 4import { logger } from '../helpers'
2 5
3function ensureIsAdmin (req, res, next) { 6function ensureIsAdmin (req: express.Request, res: express.Response, next: express.NextFunction) {
4 const user = res.locals.oauth.token.user 7 const user = res.locals.oauth.token.user
5 if (user.isAdmin() === false) { 8 if (user.isAdmin() === false) {
6 logger.info('A non admin user is trying to access to an admin content.') 9 logger.info('A non admin user is trying to access to an admin content.')
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts
index 2c1c5fa53..d71dd2452 100644
--- a/server/middlewares/index.ts
+++ b/server/middlewares/index.ts
@@ -1,8 +1,8 @@
1export * from './validators'; 1export * from './validators'
2export * from './admin'; 2export * from './admin'
3export * from './oauth'; 3export * from './oauth'
4export * from './pagination'; 4export * from './pagination'
5export * from './pods'; 5export * from './pods'
6export * from './search'; 6export * from './search'
7export * from './secure'; 7export * from './secure'
8export * from './sort'; 8export * from './sort'
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 468e41810..d545b3e58 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -1,3 +1,5 @@
1import 'express-validator'
2import * as express from 'express'
1import * as OAuthServer from 'express-oauth-server' 3import * as OAuthServer from 'express-oauth-server'
2 4
3import { OAUTH_LIFETIME } from '../initializers' 5import { OAUTH_LIFETIME } from '../initializers'
@@ -9,7 +11,7 @@ const oAuthServer = new OAuthServer({
9 model: require('../lib/oauth-model') 11 model: require('../lib/oauth-model')
10}) 12})
11 13
12function authenticate (req, res, next) { 14function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
13 oAuthServer.authenticate()(req, res, function (err) { 15 oAuthServer.authenticate()(req, res, function (err) {
14 if (err) { 16 if (err) {
15 logger.error('Cannot authenticate.', { error: err }) 17 logger.error('Cannot authenticate.', { error: err })
@@ -22,7 +24,7 @@ function authenticate (req, res, next) {
22 }) 24 })
23} 25}
24 26
25function token (req, res, next) { 27function token (req: express.Request, res: express.Response, next: express.NextFunction) {
26 return oAuthServer.token()(req, res, next) 28 return oAuthServer.token()(req, res, next)
27} 29}
28 30
diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts
index cadd76980..26a8cacf0 100644
--- a/server/middlewares/pagination.ts
+++ b/server/middlewares/pagination.ts
@@ -1,6 +1,9 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { PAGINATION_COUNT_DEFAULT } from '../initializers' 4import { PAGINATION_COUNT_DEFAULT } from '../initializers'
2 5
3function setPagination (req, res, next) { 6function setPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
4 if (!req.query.start) req.query.start = 0 7 if (!req.query.start) req.query.start = 0
5 else req.query.start = parseInt(req.query.start, 10) 8 else req.query.start = parseInt(req.query.start, 10)
6 9
diff --git a/server/middlewares/pods.ts b/server/middlewares/pods.ts
index c255be899..eaf9aa144 100644
--- a/server/middlewares/pods.ts
+++ b/server/middlewares/pods.ts
@@ -1,6 +1,9 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { REMOTE_SCHEME } from '../initializers' 4import { REMOTE_SCHEME } from '../initializers'
2 5
3function setBodyHostsPort (req, res, next) { 6function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
4 if (!req.body.hosts) return next() 7 if (!req.body.hosts) return next()
5 8
6 for (let i = 0; i < req.body.hosts.length; i++) { 9 for (let i = 0; i < req.body.hosts.length; i++) {
@@ -17,7 +20,7 @@ function setBodyHostsPort (req, res, next) {
17 return next() 20 return next()
18} 21}
19 22
20function setBodyHostPort (req, res, next) { 23function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
21 if (!req.body.host) return next() 24 if (!req.body.host) return next()
22 25
23 const hostWithPort = getHostWithPort(req.body.host) 26 const hostWithPort = getHostWithPort(req.body.host)
@@ -41,7 +44,7 @@ export {
41 44
42// --------------------------------------------------------------------------- 45// ---------------------------------------------------------------------------
43 46
44function getHostWithPort (host) { 47function getHostWithPort (host: string) {
45 const splitted = host.split(':') 48 const splitted = host.split(':')
46 49
47 // The port was not specified 50 // The port was not specified
diff --git a/server/middlewares/search.ts b/server/middlewares/search.ts
index 05a2e7442..6fe83d25b 100644
--- a/server/middlewares/search.ts
+++ b/server/middlewares/search.ts
@@ -1,4 +1,7 @@
1function setVideosSearch (req, res, next) { 1import 'express-validator'
2import * as express from 'express'
3
4function setVideosSearch (req: express.Request, res: express.Response, next: express.NextFunction) {
2 if (!req.query.field) req.query.field = 'name' 5 if (!req.query.field) req.query.field = 'name'
3 6
4 return next() 7 return next()
diff --git a/server/middlewares/secure.ts b/server/middlewares/secure.ts
index bd7cfa918..fbfd08c7b 100644
--- a/server/middlewares/secure.ts
+++ b/server/middlewares/secure.ts
@@ -1,10 +1,13 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { database as db } from '../initializers' 4import { database as db } from '../initializers'
2import { 5import {
3 logger, 6 logger,
4 checkSignature as peertubeCryptoCheckSignature 7 checkSignature as peertubeCryptoCheckSignature
5} from '../helpers' 8} from '../helpers'
6 9
7function checkSignature (req, res, next) { 10function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) {
8 const host = req.body.signature.host 11 const host = req.body.signature.host
9 db.Pod.loadByHost(host, function (err, pod) { 12 db.Pod.loadByHost(host, function (err, pod) {
10 if (err) { 13 if (err) {
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index ab9ccf524..632b2fae4 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,16 +1,19 @@
1function setUsersSort (req, res, next) { 1import 'express-validator'
2import * as express from 'express'
3
4function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
2 if (!req.query.sort) req.query.sort = '-createdAt' 5 if (!req.query.sort) req.query.sort = '-createdAt'
3 6
4 return next() 7 return next()
5} 8}
6 9
7function setVideoAbusesSort (req, res, next) { 10function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
8 if (!req.query.sort) req.query.sort = '-createdAt' 11 if (!req.query.sort) req.query.sort = '-createdAt'
9 12
10 return next() 13 return next()
11} 14}
12 15
13function setVideosSort (req, res, next) { 16function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
14 if (!req.query.sort) req.query.sort = '-createdAt' 17 if (!req.query.sort) req.query.sort = '-createdAt'
15 18
16 return next() 19 return next()
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index de719c05b..cca8295ff 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -1,7 +1,10 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { checkErrors } from './utils' 4import { checkErrors } from './utils'
2import { logger } from '../../helpers' 5import { logger } from '../../helpers'
3 6
4function paginationValidator (req, res, next) { 7function paginationValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
5 req.checkQuery('start', 'Should have a number start').optional().isInt() 8 req.checkQuery('start', 'Should have a number start').optional().isInt()
6 req.checkQuery('count', 'Should have a number count').optional().isInt() 9 req.checkQuery('count', 'Should have a number count').optional().isInt()
7 10
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts
index c55a88b85..d8eb90168 100644
--- a/server/middlewares/validators/pods.ts
+++ b/server/middlewares/validators/pods.ts
@@ -1,3 +1,6 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { database as db } from '../../initializers/database' 4import { database as db } from '../../initializers/database'
2import { checkErrors } from './utils' 5import { checkErrors } from './utils'
3import { logger } from '../../helpers' 6import { logger } from '../../helpers'
@@ -5,7 +8,7 @@ import { CONFIG } from '../../initializers'
5import { hasFriends } from '../../lib' 8import { hasFriends } from '../../lib'
6import { isTestInstance } from '../../helpers' 9import { isTestInstance } from '../../helpers'
7 10
8function makeFriendsValidator (req, res, next) { 11function makeFriendsValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
9 // Force https if the administrator wants to make friends 12 // Force https if the administrator wants to make friends
10 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { 13 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
11 return res.status(400).send('Cannot make friends with a non HTTPS webserver.') 14 return res.status(400).send('Cannot make friends with a non HTTPS webserver.')
@@ -32,7 +35,7 @@ function makeFriendsValidator (req, res, next) {
32 }) 35 })
33} 36}
34 37
35function podsAddValidator (req, res, next) { 38function podsAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
36 req.checkBody('host', 'Should have a host').isHostValid() 39 req.checkBody('host', 'Should have a host').isHostValid()
37 req.checkBody('email', 'Should have an email').isEmail() 40 req.checkBody('email', 'Should have an email').isEmail()
38 req.checkBody('publicKey', 'Should have a public key').notEmpty() 41 req.checkBody('publicKey', 'Should have a public key').notEmpty()
diff --git a/server/middlewares/validators/remote/signature.ts b/server/middlewares/validators/remote/signature.ts
index 6e3ebe7db..eb5c196eb 100644
--- a/server/middlewares/validators/remote/signature.ts
+++ b/server/middlewares/validators/remote/signature.ts
@@ -1,7 +1,10 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { logger } from '../../../helpers' 4import { logger } from '../../../helpers'
2import { checkErrors } from '../utils' 5import { checkErrors } from '../utils'
3 6
4function signatureValidator (req, res, next) { 7function signatureValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
5 req.checkBody('signature.host', 'Should have a signature host').isURL() 8 req.checkBody('signature.host', 'Should have a signature host').isURL()
6 req.checkBody('signature.signature', 'Should have a signature').notEmpty() 9 req.checkBody('signature.signature', 'Should have a signature').notEmpty()
7 10
diff --git a/server/middlewares/validators/remote/videos.ts b/server/middlewares/validators/remote/videos.ts
index 3380c29e2..2037c0085 100644
--- a/server/middlewares/validators/remote/videos.ts
+++ b/server/middlewares/validators/remote/videos.ts
@@ -1,7 +1,10 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { logger } from '../../../helpers' 4import { logger } from '../../../helpers'
2import { checkErrors } from '../utils' 5import { checkErrors } from '../utils'
3 6
4function remoteVideosValidator (req, res, next) { 7function remoteVideosValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
5 req.checkBody('data').isEachRemoteRequestVideosValid() 8 req.checkBody('data').isEachRemoteRequestVideosValid()
6 9
7 logger.debug('Checking remoteVideos parameters', { parameters: req.body }) 10 logger.debug('Checking remoteVideos parameters', { parameters: req.body })
@@ -9,7 +12,7 @@ function remoteVideosValidator (req, res, next) {
9 checkErrors(req, res, next) 12 checkErrors(req, res, next)
10} 13}
11 14
12function remoteQaduVideosValidator (req, res, next) { 15function remoteQaduVideosValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
13 req.checkBody('data').isEachRemoteRequestVideosQaduValid() 16 req.checkBody('data').isEachRemoteRequestVideosQaduValid()
14 17
15 logger.debug('Checking remoteQaduVideos parameters', { parameters: req.body }) 18 logger.debug('Checking remoteQaduVideos parameters', { parameters: req.body })
@@ -17,7 +20,7 @@ function remoteQaduVideosValidator (req, res, next) {
17 checkErrors(req, res, next) 20 checkErrors(req, res, next)
18} 21}
19 22
20function remoteEventsVideosValidator (req, res, next) { 23function remoteEventsVideosValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
21 req.checkBody('data').isEachRemoteRequestVideosEventsValid() 24 req.checkBody('data').isEachRemoteRequestVideosEventsValid()
22 25
23 logger.debug('Checking remoteEventsVideos parameters', { parameters: req.body }) 26 logger.debug('Checking remoteEventsVideos parameters', { parameters: req.body })
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index ebc7333c7..3baee9fb3 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,3 +1,6 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { checkErrors } from './utils' 4import { checkErrors } from './utils'
2import { logger } from '../../helpers' 5import { logger } from '../../helpers'
3import { SORTABLE_COLUMNS } from '../../initializers' 6import { SORTABLE_COLUMNS } from '../../initializers'
@@ -7,15 +10,15 @@ const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS)
7const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
8const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
9 12
10function usersSortValidator (req, res, next) { 13function usersSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
11 checkSort(req, res, next, SORTABLE_USERS_COLUMNS) 14 checkSort(req, res, next, SORTABLE_USERS_COLUMNS)
12} 15}
13 16
14function videoAbusesSortValidator (req, res, next) { 17function videoAbusesSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
15 checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS) 18 checkSort(req, res, next, SORTABLE_VIDEO_ABUSES_COLUMNS)
16} 19}
17 20
18function videosSortValidator (req, res, next) { 21function videosSortValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
19 checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS) 22 checkSort(req, res, next, SORTABLE_VIDEOS_COLUMNS)
20} 23}
21 24
@@ -29,7 +32,7 @@ export {
29 32
30// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
31 34
32function checkSort (req, res, next, sortableColumns) { 35function checkSort (req: express.Request, res: express.Response, next: express.NextFunction, sortableColumns: string[]) {
33 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns) 36 req.checkQuery('sort', 'Should have correct sortable column').optional().isIn(sortableColumns)
34 37
35 logger.debug('Checking sort parameters', { parameters: req.query }) 38 logger.debug('Checking sort parameters', { parameters: req.query })
@@ -37,7 +40,7 @@ function checkSort (req, res, next, sortableColumns) {
37 checkErrors(req, res, next) 40 checkErrors(req, res, next)
38} 41}
39 42
40function createSortableColumns (sortableColumns) { 43function createSortableColumns (sortableColumns: string[]) {
41 const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn) 44 const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn)
42 45
43 return sortableColumns.concat(sortableColumnDesc) 46 return sortableColumns.concat(sortableColumnDesc)
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index e0d1d917a..b7b9ef370 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,8 +1,11 @@
1import 'express-validator'
2import * as express from 'express'
3
1import { database as db } from '../../initializers/database' 4import { database as db } from '../../initializers/database'
2import { checkErrors } from './utils' 5import { checkErrors } from './utils'
3import { logger } from '../../helpers' 6import { logger } from '../../helpers'
4 7
5function usersAddValidator (req, res, next) { 8function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
6 req.checkBody('username', 'Should have a valid username').isUserUsernameValid() 9 req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
7 req.checkBody('password', 'Should have a valid password').isUserPasswordValid() 10 req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
8 req.checkBody('email', 'Should have a valid email').isEmail() 11 req.checkBody('email', 'Should have a valid email').isEmail()
@@ -23,7 +26,7 @@ function usersAddValidator (req, res, next) {
23 }) 26 })
24} 27}
25 28
26function usersRemoveValidator (req, res, next) { 29function usersRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
27 req.checkParams('id', 'Should have a valid id').notEmpty().isInt() 30 req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
28 31
29 logger.debug('Checking usersRemove parameters', { parameters: req.params }) 32 logger.debug('Checking usersRemove parameters', { parameters: req.params })
@@ -44,7 +47,7 @@ function usersRemoveValidator (req, res, next) {
44 }) 47 })
45} 48}
46 49
47function usersUpdateValidator (req, res, next) { 50function usersUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
48 req.checkParams('id', 'Should have a valid id').notEmpty().isInt() 51 req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
49 // Add old password verification 52 // Add old password verification
50 req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid() 53 req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid()
@@ -55,7 +58,7 @@ function usersUpdateValidator (req, res, next) {
55 checkErrors(req, res, next) 58 checkErrors(req, res, next)
56} 59}
57 60
58function usersVideoRatingValidator (req, res, next) { 61function usersVideoRatingValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
59 req.checkParams('videoId', 'Should have a valid video id').notEmpty().isUUID(4) 62 req.checkParams('videoId', 'Should have a valid video id').notEmpty().isUUID(4)
60 63
61 logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) 64 logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index 710e65529..0424d5942 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,9 +1,10 @@
1import 'express-validator'
2import * as express from 'express'
1import { inspect } from 'util' 3import { inspect } from 'util'
2 4
3import { logger } from '../../helpers' 5import { logger } from '../../helpers'
4 6
5function checkErrors (req, res, next, statusCode?) { 7function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) {
6 if (statusCode === undefined) statusCode = 400
7 const errors = req.validationErrors() 8 const errors = req.validationErrors()
8 9
9 if (errors) { 10 if (errors) {
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index 47825975c..e99cdefb1 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -1,9 +1,13 @@
1import 'express-validator'
2import * as multer from 'multer'
3import * as express from 'express'
4
1import { database as db } from '../../initializers/database' 5import { database as db } from '../../initializers/database'
2import { checkErrors } from './utils' 6import { checkErrors } from './utils'
3import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' 7import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
4import { logger, isVideoDurationValid } from '../../helpers' 8import { logger, isVideoDurationValid } from '../../helpers'
5 9
6function videosAddValidator (req, res, next) { 10function videosAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
7 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) 11 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
8 req.checkBody('name', 'Should have a valid name').isVideoNameValid() 12 req.checkBody('name', 'Should have a valid name').isVideoNameValid()
9 req.checkBody('category', 'Should have a valid category').isVideoCategoryValid() 13 req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
@@ -27,13 +31,13 @@ function videosAddValidator (req, res, next) {
27 return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') 31 return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).')
28 } 32 }
29 33
30 videoFile.duration = duration 34 videoFile['duration'] = duration
31 next() 35 next()
32 }) 36 })
33 }) 37 })
34} 38}
35 39
36function videosUpdateValidator (req, res, next) { 40function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
37 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 41 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
38 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() 42 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
39 req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() 43 req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
@@ -61,7 +65,7 @@ function videosUpdateValidator (req, res, next) {
61 }) 65 })
62} 66}
63 67
64function videosGetValidator (req, res, next) { 68function videosGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
65 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 69 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
66 70
67 logger.debug('Checking videosGet parameters', { parameters: req.params }) 71 logger.debug('Checking videosGet parameters', { parameters: req.params })
@@ -71,7 +75,7 @@ function videosGetValidator (req, res, next) {
71 }) 75 })
72} 76}
73 77
74function videosRemoveValidator (req, res, next) { 78function videosRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
75 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 79 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
76 80
77 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 81 logger.debug('Checking videosRemove parameters', { parameters: req.params })
@@ -88,7 +92,7 @@ function videosRemoveValidator (req, res, next) {
88 }) 92 })
89} 93}
90 94
91function videosSearchValidator (req, res, next) { 95function videosSearchValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
92 const searchableColumns = SEARCHABLE_COLUMNS.VIDEOS 96 const searchableColumns = SEARCHABLE_COLUMNS.VIDEOS
93 req.checkParams('value', 'Should have a valid search').notEmpty() 97 req.checkParams('value', 'Should have a valid search').notEmpty()
94 req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) 98 req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns)
@@ -98,7 +102,7 @@ function videosSearchValidator (req, res, next) {
98 checkErrors(req, res, next) 102 checkErrors(req, res, next)
99} 103}
100 104
101function videoAbuseReportValidator (req, res, next) { 105function videoAbuseReportValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
102 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 106 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
103 req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid() 107 req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid()
104 108
@@ -109,7 +113,7 @@ function videoAbuseReportValidator (req, res, next) {
109 }) 113 })
110} 114}
111 115
112function videoRateValidator (req, res, next) { 116function videoRateValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
113 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 117 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
114 req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() 118 req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid()
115 119
@@ -120,7 +124,7 @@ function videoRateValidator (req, res, next) {
120 }) 124 })
121} 125}
122 126
123function videosBlacklistValidator (req, res, next) { 127function videosBlacklistValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
124 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 128 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
125 129
126 logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) 130 logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
@@ -150,7 +154,7 @@ export {
150 154
151// --------------------------------------------------------------------------- 155// ---------------------------------------------------------------------------
152 156
153function checkVideoExists (id, res, callback) { 157function checkVideoExists (id: string, res: express.Response, callback: () => void) {
154 db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) { 158 db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) {
155 if (err) { 159 if (err) {
156 logger.error('Error in video request validator.', { error: err }) 160 logger.error('Error in video request validator.', { error: err })
@@ -164,7 +168,7 @@ function checkVideoExists (id, res, callback) {
164 }) 168 })
165} 169}
166 170
167function checkUserCanDeleteVideo (userId, res, callback) { 171function checkUserCanDeleteVideo (userId: number, res: express.Response, callback: () => void) {
168 // Retrieve the user who did the request 172 // Retrieve the user who did the request
169 db.User.loadById(userId, function (err, user) { 173 db.User.loadById(userId, function (err, user) {
170 if (err) { 174 if (err) {
@@ -190,7 +194,7 @@ function checkUserCanDeleteVideo (userId, res, callback) {
190 }) 194 })
191} 195}
192 196
193function checkVideoIsBlacklistable (req, res, callback) { 197function checkVideoIsBlacklistable (req: express.Request, res: express.Response, callback: () => void) {
194 if (res.locals.video.isOwned() === true) { 198 if (res.locals.video.isOwned() === true) {
195 return res.status(403).send('Cannot blacklist a local video') 199 return res.status(403).send('Cannot blacklist a local video')
196 } 200 }