diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/account.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/activity.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/signature.ts | 7 | ||||
-rw-r--r-- | server/middlewares/validators/follows.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/oembed.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/pagination.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 9 | ||||
-rw-r--r-- | server/middlewares/validators/utils.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/video-blacklist.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/video-comments.ts | 22 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 17 | ||||
-rw-r--r-- | server/middlewares/validators/webfinger.ts | 3 |
14 files changed, 48 insertions, 38 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 6951dfc80..3573a9a50 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | 6 | ||
7 | const localAccountValidator = [ | 7 | const localAccountValidator = [ |
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index e0225f30c..208e23f86 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator/check' |
3 | import { logger } from '../../../helpers' | 3 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' |
4 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | 6 | ||
7 | const activityPubValidator = [ | 7 | const activityPubValidator = [ |
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts index d41bb6a8d..4efe9aafa 100644 --- a/server/middlewares/validators/activitypub/signature.ts +++ b/server/middlewares/validators/activitypub/signature.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator/check' |
3 | import { logger } from '../../../helpers' | 3 | import { |
4 | import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' | 4 | isSignatureCreatorValid, isSignatureTypeValid, |
5 | isSignatureValueValid | ||
6 | } from '../../../helpers/custom-validators/activitypub/signature' | ||
5 | import { isDateValid } from '../../../helpers/custom-validators/misc' | 7 | import { isDateValid } from '../../../helpers/custom-validators/misc' |
8 | import { logger } from '../../../helpers/logger' | ||
6 | import { areValidationErrors } from '../utils' | 9 | import { areValidationErrors } from '../utils' |
7 | 10 | ||
8 | const signatureValidator = [ | 11 | const signatureValidator = [ |
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 2240d30db..7dadf6a19 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { getServerActor, isTestInstance, logger } from '../../helpers' | 3 | import { isTestInstance } from '../../helpers/core-utils' |
4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | ||
6 | import { getServerActor } from '../../helpers/utils' | ||
5 | import { CONFIG } from '../../initializers' | 7 | import { CONFIG } from '../../initializers' |
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
7 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index fb7b726e5..cd9b27b16 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestInstance, logger } from '../../helpers' | 4 | import { isTestInstance } from '../../helpers/core-utils' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 6 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
7 | import { logger } from '../../helpers/logger' | ||
7 | import { CONFIG } from '../../initializers' | 8 | import { CONFIG } from '../../initializers' |
8 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
9 | 10 | ||
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 25debfa6e..e1ed8cd65 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | 5 | ||
6 | const paginationValidator = [ | 6 | const paginationValidator = [ |
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index 56855bda0..e1d8d7d1b 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { query } from 'express-validator/check' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { logger } from '../../helpers' | 2 | import { query } from 'express-validator/check' |
3 | import { logger } from '../../helpers/logger' | ||
4 | import { SORTABLE_COLUMNS } from '../../initializers' | 4 | import { SORTABLE_COLUMNS } from '../../initializers' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | 6 | ||
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index a6fdbe268..db40a5c88 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -1,17 +1,14 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { isSignupAllowed, logger } from '../../helpers' | ||
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { | 5 | import { |
7 | isUserDisplayNSFWValid, | 6 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, |
8 | isUserAutoPlayVideoValid, | ||
9 | isUserPasswordValid, | ||
10 | isUserRoleValid, | ||
11 | isUserUsernameValid, | ||
12 | isUserVideoQuotaValid | 7 | isUserVideoQuotaValid |
13 | } from '../../helpers/custom-validators/users' | 8 | } from '../../helpers/custom-validators/users' |
14 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 9 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
10 | import { logger } from '../../helpers/logger' | ||
11 | import { isSignupAllowed } from '../../helpers/utils' | ||
15 | import { UserModel } from '../../models/account/user' | 12 | import { UserModel } from '../../models/account/user' |
16 | import { areValidationErrors } from './utils' | 13 | import { areValidationErrors } from './utils' |
17 | 14 | ||
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 61f76b457..55b140103 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { validationResult } from 'express-validator/check' | 2 | import { validationResult } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers/logger' |
4 | 4 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 5 | function areValidationErrors (req: express.Request, res: express.Response) { |
6 | const errors = validationResult(req) | 6 | const errors = validationResult(req) |
diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts index 98099fe3f..3c1ef1b4e 100644 --- a/server/middlewares/validators/video-blacklist.ts +++ b/server/middlewares/validators/video-blacklist.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 4 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
5 | import { logger } from '../../helpers/logger' | ||
6 | import { VideoModel } from '../../models/video/video' | 6 | import { VideoModel } from '../../models/video/video' |
7 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | 7 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' |
8 | import { areValidationErrors } from './utils' | 8 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 0e6eff493..86bddde82 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { logger } from '../../helpers' | ||
5 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' |
6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
7 | import { | 6 | import { |
8 | isVideoChannelDescriptionValid, | 7 | isVideoChannelDescriptionValid, isVideoChannelExist, |
9 | isVideoChannelExist, | ||
10 | isVideoChannelNameValid | 8 | isVideoChannelNameValid |
11 | } from '../../helpers/custom-validators/video-channels' | 9 | } from '../../helpers/custom-validators/video-channels' |
10 | import { logger } from '../../helpers/logger' | ||
12 | import { UserModel } from '../../models/account/user' | 11 | import { UserModel } from '../../models/account/user' |
13 | import { VideoChannelModel } from '../../models/video/video-channel' | 12 | import { VideoChannelModel } from '../../models/video/video-channel' |
14 | import { areValidationErrors } from './utils' | 13 | import { areValidationErrors } from './utils' |
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts index 1d19fac58..fdd092571 100644 --- a/server/middlewares/validators/video-comments.ts +++ b/server/middlewares/validators/video-comments.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' | 4 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' |
6 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 5 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
6 | import { logger } from '../../helpers/logger' | ||
7 | import { VideoModel } from '../../models/video/video' | 7 | import { VideoModel } from '../../models/video/video' |
8 | import { VideoCommentModel } from '../../models/video/video-comment' | 8 | import { VideoCommentModel } from '../../models/video/video-comment' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [ | |||
66 | } | 66 | } |
67 | ] | 67 | ] |
68 | 68 | ||
69 | const videoCommentGetValidator = [ | ||
70 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
71 | param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), | ||
72 | |||
73 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
74 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) | ||
75 | |||
76 | if (areValidationErrors(req, res)) return | ||
77 | if (!await isVideoExist(req.params.videoId, res)) return | ||
78 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | ||
79 | |||
80 | return next() | ||
81 | } | ||
82 | ] | ||
83 | |||
69 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |
70 | 85 | ||
71 | export { | 86 | export { |
72 | listVideoCommentThreadsValidator, | 87 | listVideoCommentThreadsValidator, |
73 | listVideoThreadCommentsValidator, | 88 | listVideoThreadCommentsValidator, |
74 | addVideoCommentThreadValidator, | 89 | addVideoCommentThreadValidator, |
75 | addVideoCommentReplyValidator | 90 | addVideoCommentReplyValidator, |
91 | videoCommentGetValidator | ||
76 | } | 92 | } |
77 | 93 | ||
78 | // --------------------------------------------------------------------------- | 94 | // --------------------------------------------------------------------------- |
@@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex | |||
109 | } | 125 | } |
110 | 126 | ||
111 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { | 127 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { |
112 | const videoComment = await VideoCommentModel.loadById(id) | 128 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) |
113 | 129 | ||
114 | if (!videoComment) { | 130 | if (!videoComment) { |
115 | res.status(404) | 131 | res.status(404) |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index b52d5f285..bffc50322 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -2,22 +2,13 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { getDurationFromVideoFile, logger } from '../../helpers' | ||
6 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
7 | import { | 6 | import { |
8 | isVideoAbuseReasonValid, | 7 | isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid, |
9 | isVideoCategoryValid, | 8 | isVideoLicenceValid, isVideoNameValid, isVideoNSFWValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid |
10 | isVideoDescriptionValid, | ||
11 | isVideoExist, | ||
12 | isVideoFile, | ||
13 | isVideoLanguageValid, | ||
14 | isVideoLicenceValid, | ||
15 | isVideoNameValid, | ||
16 | isVideoNSFWValid, | ||
17 | isVideoPrivacyValid, | ||
18 | isVideoRatingTypeValid, | ||
19 | isVideoTagsValid | ||
20 | } from '../../helpers/custom-validators/videos' | 9 | } from '../../helpers/custom-validators/videos' |
10 | import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils' | ||
11 | import { logger } from '../../helpers/logger' | ||
21 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 12 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
22 | import { UserModel } from '../../models/account/user' | 13 | import { UserModel } from '../../models/account/user' |
23 | import { VideoModel } from '../../models/video/video' | 14 | import { VideoModel } from '../../models/video/video' |
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 894c72498..3dbec6e44 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { getHostWithPort, logger } from '../../helpers' | ||
4 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' | 3 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { getHostWithPort } from '../../helpers/utils' | ||
5 | import { ActorModel } from '../../models/activitypub/actor' | 6 | import { ActorModel } from '../../models/activitypub/actor' |
6 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
7 | 8 | ||