diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
commit | 0f6acda11681de90d38dd18669863c6e270851ee (patch) | |
tree | b3b28e00d539645f5a810202dc8afada289e7b2e /server/middlewares/validators | |
parent | 9a18a6252071cf21b18f82a24bb63078abb75bc1 (diff) | |
download | PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.gz PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.zst PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.zip |
Does exist
Diffstat (limited to 'server/middlewares/validators')
18 files changed, 99 insertions, 99 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 88c57eaa1..96e120a38 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,6 +1,6 @@ | |||
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 { isAccountNameValid, isAccountNameWithHostExist, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | 6 | ||
@@ -11,7 +11,7 @@ const localAccountValidator = [ | |||
11 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) | 11 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) |
12 | 12 | ||
13 | if (areValidationErrors(req, res)) return | 13 | if (areValidationErrors(req, res)) return |
14 | if (!await isLocalAccountNameExist(req.params.name, res)) return | 14 | if (!await doesLocalAccountNameExist(req.params.name, res)) return |
15 | 15 | ||
16 | return next() | 16 | return next() |
17 | } | 17 | } |
@@ -24,7 +24,7 @@ const accountNameWithHostGetValidator = [ | |||
24 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) | 24 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) |
25 | 25 | ||
26 | if (areValidationErrors(req, res)) return | 26 | if (areValidationErrors(req, res)) return |
27 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | 27 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
28 | 28 | ||
29 | return next() | 29 | return next() |
30 | } | 30 | } |
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 109276c63..d7ec649b6 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -2,7 +2,7 @@ import { body, param } from 'express-validator/check' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 5 | import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
6 | import { UserModel } from '../../models/account/user' | 6 | import { UserModel } from '../../models/account/user' |
7 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 7 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
8 | import { isHostValid } from '../../helpers/custom-validators/servers' | 8 | import { isHostValid } from '../../helpers/custom-validators/servers' |
@@ -18,7 +18,7 @@ const blockAccountValidator = [ | |||
18 | logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) | 18 | logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) |
19 | 19 | ||
20 | if (areValidationErrors(req, res)) return | 20 | if (areValidationErrors(req, res)) return |
21 | if (!await isAccountNameWithHostExist(req.body.accountName, res)) return | 21 | if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return |
22 | 22 | ||
23 | const user = res.locals.oauth.token.User as UserModel | 23 | const user = res.locals.oauth.token.User as UserModel |
24 | const accountToBlock = res.locals.account | 24 | const accountToBlock = res.locals.account |
@@ -42,11 +42,11 @@ const unblockAccountByAccountValidator = [ | |||
42 | logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) | 42 | logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) |
43 | 43 | ||
44 | if (areValidationErrors(req, res)) return | 44 | if (areValidationErrors(req, res)) return |
45 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | 45 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
46 | 46 | ||
47 | const user = res.locals.oauth.token.User as UserModel | 47 | const user = res.locals.oauth.token.User as UserModel |
48 | const targetAccount = res.locals.account | 48 | const targetAccount = res.locals.account |
49 | if (!await isUnblockAccountExists(user.Account.id, targetAccount.id, res)) return | 49 | if (!await doesUnblockAccountExist(user.Account.id, targetAccount.id, res)) return |
50 | 50 | ||
51 | return next() | 51 | return next() |
52 | } | 52 | } |
@@ -59,11 +59,11 @@ const unblockAccountByServerValidator = [ | |||
59 | logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) | 59 | logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) |
60 | 60 | ||
61 | if (areValidationErrors(req, res)) return | 61 | if (areValidationErrors(req, res)) return |
62 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | 62 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
63 | 63 | ||
64 | const serverActor = await getServerActor() | 64 | const serverActor = await getServerActor() |
65 | const targetAccount = res.locals.account | 65 | const targetAccount = res.locals.account |
66 | if (!await isUnblockAccountExists(serverActor.Account.id, targetAccount.id, res)) return | 66 | if (!await doesUnblockAccountExist(serverActor.Account.id, targetAccount.id, res)) return |
67 | 67 | ||
68 | return next() | 68 | return next() |
69 | } | 69 | } |
@@ -107,7 +107,7 @@ const unblockServerByAccountValidator = [ | |||
107 | if (areValidationErrors(req, res)) return | 107 | if (areValidationErrors(req, res)) return |
108 | 108 | ||
109 | const user = res.locals.oauth.token.User as UserModel | 109 | const user = res.locals.oauth.token.User as UserModel |
110 | if (!await isUnblockServerExists(user.Account.id, req.params.host, res)) return | 110 | if (!await doesUnblockServerExist(user.Account.id, req.params.host, res)) return |
111 | 111 | ||
112 | return next() | 112 | return next() |
113 | } | 113 | } |
@@ -122,7 +122,7 @@ const unblockServerByServerValidator = [ | |||
122 | if (areValidationErrors(req, res)) return | 122 | if (areValidationErrors(req, res)) return |
123 | 123 | ||
124 | const serverActor = await getServerActor() | 124 | const serverActor = await getServerActor() |
125 | if (!await isUnblockServerExists(serverActor.Account.id, req.params.host, res)) return | 125 | if (!await doesUnblockServerExist(serverActor.Account.id, req.params.host, res)) return |
126 | 126 | ||
127 | return next() | 127 | return next() |
128 | } | 128 | } |
@@ -141,7 +141,7 @@ export { | |||
141 | 141 | ||
142 | // --------------------------------------------------------------------------- | 142 | // --------------------------------------------------------------------------- |
143 | 143 | ||
144 | async function isUnblockAccountExists (accountId: number, targetAccountId: number, res: express.Response) { | 144 | async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { |
145 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) | 145 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) |
146 | if (!accountBlock) { | 146 | if (!accountBlock) { |
147 | res.status(404) | 147 | res.status(404) |
@@ -156,7 +156,7 @@ async function isUnblockAccountExists (accountId: number, targetAccountId: numbe | |||
156 | return true | 156 | return true |
157 | } | 157 | } |
158 | 158 | ||
159 | async function isUnblockServerExists (accountId: number, host: string, res: express.Response) { | 159 | async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { |
160 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) | 160 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) |
161 | if (!serverBlock) { | 161 | if (!serverBlock) { |
162 | res.status(404) | 162 | res.status(404) |
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index 969ce2526..e4f5c98fe 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | 2 | import { param, query } from 'express-validator/check' |
3 | import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 3 | import { doesAccountIdExist, isAccountNameValid, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | 7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' |
8 | import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' | 8 | import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' |
9 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 9 | import { doesVideoExist } from '../../helpers/custom-validators/videos' |
10 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | 10 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' |
11 | 11 | ||
12 | const videoFeedsValidator = [ | 12 | const videoFeedsValidator = [ |
@@ -22,10 +22,10 @@ const videoFeedsValidator = [ | |||
22 | 22 | ||
23 | if (areValidationErrors(req, res)) return | 23 | if (areValidationErrors(req, res)) return |
24 | 24 | ||
25 | if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return | 25 | if (req.query.accountId && !await doesAccountIdExist(req.query.accountId, res)) return |
26 | if (req.query.videoChannelId && !await isVideoChannelIdExist(req.query.videoChannelId, res)) return | 26 | if (req.query.videoChannelId && !await doesVideoChannelIdExist(req.query.videoChannelId, res)) return |
27 | if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return | 27 | if (req.query.accountName && !await doesAccountNameWithHostExist(req.query.accountName, res)) return |
28 | if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return | 28 | if (req.query.videoChannelName && !await doesVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return |
29 | 29 | ||
30 | return next() | 30 | return next() |
31 | } | 31 | } |
@@ -41,7 +41,7 @@ const videoCommentsFeedsValidator = [ | |||
41 | 41 | ||
42 | if (areValidationErrors(req, res)) return | 42 | if (areValidationErrors(req, res)) return |
43 | 43 | ||
44 | if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return | 44 | if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return |
45 | 45 | ||
46 | return next() | 46 | return next() |
47 | } | 47 | } |
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index cd9b27b16..c89bc26de 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -3,7 +3,7 @@ import { query } from 'express-validator/check' | |||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestInstance } from '../../helpers/core-utils' | 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 { doesVideoExist } from '../../helpers/custom-validators/videos' |
7 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
8 | import { CONFIG } from '../../initializers' | 8 | import { CONFIG } from '../../initializers' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
@@ -52,7 +52,7 @@ const oembedValidator = [ | |||
52 | .end() | 52 | .end() |
53 | } | 53 | } |
54 | 54 | ||
55 | if (!await isVideoExist(videoId, res)) return | 55 | if (!await doesVideoExist(videoId, res)) return |
56 | 56 | ||
57 | return next() | 57 | return next() |
58 | } | 58 | } |
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index 329322509..419921928 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { param, body } from 'express-validator/check' | 3 | import { param, body } from 'express-validator/check' |
4 | import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' | 4 | import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' |
5 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 5 | import { doesVideoExist } from '../../helpers/custom-validators/videos' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
8 | import { VideoModel } from '../../models/video/video' | 8 | import { VideoModel } from '../../models/video/video' |
@@ -27,7 +27,7 @@ const videoFileRedundancyGetValidator = [ | |||
27 | logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params }) | 27 | logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params }) |
28 | 28 | ||
29 | if (areValidationErrors(req, res)) return | 29 | if (areValidationErrors(req, res)) return |
30 | if (!await isVideoExist(req.params.videoId, res)) return | 30 | if (!await doesVideoExist(req.params.videoId, res)) return |
31 | 31 | ||
32 | const video: VideoModel = res.locals.video | 32 | const video: VideoModel = res.locals.video |
33 | const videoFile = video.VideoFiles.find(f => { | 33 | const videoFile = video.VideoFiles.find(f => { |
@@ -53,7 +53,7 @@ const videoPlaylistRedundancyGetValidator = [ | |||
53 | logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) | 53 | logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) |
54 | 54 | ||
55 | if (areValidationErrors(req, res)) return | 55 | if (areValidationErrors(req, res)) return |
56 | if (!await isVideoExist(req.params.videoId, res)) return | 56 | if (!await doesVideoExist(req.params.videoId, res)) return |
57 | 57 | ||
58 | const video: VideoModel = res.locals.video | 58 | const video: VideoModel = res.locals.video |
59 | const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType) | 59 | const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType) |
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index d85afc2ff..e62a17163 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts | |||
@@ -57,7 +57,7 @@ const contactAdministratorValidator = [ | |||
57 | .end() | 57 | .end() |
58 | } | 58 | } |
59 | 59 | ||
60 | if (await Redis.Instance.isContactFormIpExists(req.ip)) { | 60 | if (await Redis.Instance.doesContactFormIpExist(req.ip)) { |
61 | logger.info('Refusing a contact form by %s: already sent one recently.', req.ip) | 61 | logger.info('Refusing a contact form by %s: already sent one recently.', req.ip) |
62 | 62 | ||
63 | return res | 63 | return res |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index a52e3060a..5e8c8c29b 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | isUserVideoQuotaDailyValid, | 16 | isUserVideoQuotaDailyValid, |
17 | isUserVideoQuotaValid, isUserVideosHistoryEnabledValid | 17 | isUserVideoQuotaValid, isUserVideosHistoryEnabledValid |
18 | } from '../../helpers/custom-validators/users' | 18 | } from '../../helpers/custom-validators/users' |
19 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 19 | import { doesVideoExist } from '../../helpers/custom-validators/videos' |
20 | import { logger } from '../../helpers/logger' | 20 | import { logger } from '../../helpers/logger' |
21 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 21 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
22 | import { Redis } from '../../lib/redis' | 22 | import { Redis } from '../../lib/redis' |
@@ -194,7 +194,7 @@ const usersVideoRatingValidator = [ | |||
194 | logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) | 194 | logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) |
195 | 195 | ||
196 | if (areValidationErrors(req, res)) return | 196 | if (areValidationErrors(req, res)) return |
197 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 197 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return |
198 | 198 | ||
199 | return next() | 199 | return next() |
200 | } | 200 | } |
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index be26ca16a..d1910a992 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -2,11 +2,11 @@ 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 { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 5 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { areValidationErrors } from '../utils' | 7 | import { areValidationErrors } from '../utils' |
8 | import { | 8 | import { |
9 | isVideoAbuseExist, | 9 | doesVideoAbuseExist, |
10 | isVideoAbuseModerationCommentValid, | 10 | isVideoAbuseModerationCommentValid, |
11 | isVideoAbuseReasonValid, | 11 | isVideoAbuseReasonValid, |
12 | isVideoAbuseStateValid | 12 | isVideoAbuseStateValid |
@@ -20,7 +20,7 @@ const videoAbuseReportValidator = [ | |||
20 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | 20 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) |
21 | 21 | ||
22 | if (areValidationErrors(req, res)) return | 22 | if (areValidationErrors(req, res)) return |
23 | if (!await isVideoExist(req.params.videoId, res)) return | 23 | if (!await doesVideoExist(req.params.videoId, res)) return |
24 | 24 | ||
25 | return next() | 25 | return next() |
26 | } | 26 | } |
@@ -34,8 +34,8 @@ const videoAbuseGetValidator = [ | |||
34 | logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) | 34 | logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) |
35 | 35 | ||
36 | if (areValidationErrors(req, res)) return | 36 | if (areValidationErrors(req, res)) return |
37 | if (!await isVideoExist(req.params.videoId, res)) return | 37 | if (!await doesVideoExist(req.params.videoId, res)) return |
38 | if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return | 38 | if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return |
39 | 39 | ||
40 | return next() | 40 | return next() |
41 | } | 41 | } |
@@ -55,8 +55,8 @@ const videoAbuseUpdateValidator = [ | |||
55 | logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) | 55 | logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) |
56 | 56 | ||
57 | if (areValidationErrors(req, res)) return | 57 | if (areValidationErrors(req, res)) return |
58 | if (!await isVideoExist(req.params.videoId, res)) return | 58 | if (!await doesVideoExist(req.params.videoId, res)) return |
59 | if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return | 59 | if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return |
60 | 60 | ||
61 | return next() | 61 | return next() |
62 | } | 62 | } |
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 2688f63ae..77ad29cbb 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -1,10 +1,10 @@ | |||
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 { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 4 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' | 7 | import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' |
8 | import { VideoModel } from '../../../models/video/video' | 8 | import { VideoModel } from '../../../models/video/video' |
9 | 9 | ||
10 | const videosBlacklistRemoveValidator = [ | 10 | const videosBlacklistRemoveValidator = [ |
@@ -14,8 +14,8 @@ const videosBlacklistRemoveValidator = [ | |||
14 | logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) | 14 | logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) |
15 | 15 | ||
16 | if (areValidationErrors(req, res)) return | 16 | if (areValidationErrors(req, res)) return |
17 | if (!await isVideoExist(req.params.videoId, res)) return | 17 | if (!await doesVideoExist(req.params.videoId, res)) return |
18 | if (!await isVideoBlacklistExist(res.locals.video.id, res)) return | 18 | if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return |
19 | 19 | ||
20 | return next() | 20 | return next() |
21 | } | 21 | } |
@@ -35,7 +35,7 @@ const videosBlacklistAddValidator = [ | |||
35 | logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) | 35 | logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) |
36 | 36 | ||
37 | if (areValidationErrors(req, res)) return | 37 | if (areValidationErrors(req, res)) return |
38 | if (!await isVideoExist(req.params.videoId, res)) return | 38 | if (!await doesVideoExist(req.params.videoId, res)) return |
39 | 39 | ||
40 | const video: VideoModel = res.locals.video | 40 | const video: VideoModel = res.locals.video |
41 | if (req.body.unfederate === true && video.remote === true) { | 41 | if (req.body.unfederate === true && video.remote === true) { |
@@ -59,8 +59,8 @@ const videosBlacklistUpdateValidator = [ | |||
59 | logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params }) | 59 | logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params }) |
60 | 60 | ||
61 | if (areValidationErrors(req, res)) return | 61 | if (areValidationErrors(req, res)) return |
62 | if (!await isVideoExist(req.params.videoId, res)) return | 62 | if (!await doesVideoExist(req.params.videoId, res)) return |
63 | if (!await isVideoBlacklistExist(res.locals.video.id, res)) return | 63 | if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return |
64 | 64 | ||
65 | return next() | 65 | return next() |
66 | } | 66 | } |
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index 63d84fbec..b2b259aff 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from '../utils' | 2 | import { areValidationErrors } from '../utils' |
3 | import { checkUserCanManageVideo, isVideoExist } from '../../../helpers/custom-validators/videos' | 3 | import { checkUserCanManageVideo, doesVideoExist } from '../../../helpers/custom-validators/videos' |
4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { body, param } from 'express-validator/check' | 5 | import { body, param } from 'express-validator/check' |
6 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 6 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
7 | import { UserRight } from '../../../../shared' | 7 | import { UserRight } from '../../../../shared' |
8 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
9 | import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' | 9 | import { doesVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' |
10 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 10 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
11 | 11 | ||
12 | const addVideoCaptionValidator = [ | 12 | const addVideoCaptionValidator = [ |
@@ -22,7 +22,7 @@ const addVideoCaptionValidator = [ | |||
22 | logger.debug('Checking addVideoCaption parameters', { parameters: req.body }) | 22 | logger.debug('Checking addVideoCaption parameters', { parameters: req.body }) |
23 | 23 | ||
24 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | 24 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
25 | if (!await isVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) | 25 | if (!await doesVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) |
26 | 26 | ||
27 | // Check if the user who did the request is able to update the video | 27 | // Check if the user who did the request is able to update the video |
28 | const user = res.locals.oauth.token.User | 28 | const user = res.locals.oauth.token.User |
@@ -40,8 +40,8 @@ const deleteVideoCaptionValidator = [ | |||
40 | logger.debug('Checking deleteVideoCaption parameters', { parameters: req.params }) | 40 | logger.debug('Checking deleteVideoCaption parameters', { parameters: req.params }) |
41 | 41 | ||
42 | if (areValidationErrors(req, res)) return | 42 | if (areValidationErrors(req, res)) return |
43 | if (!await isVideoExist(req.params.videoId, res)) return | 43 | if (!await doesVideoExist(req.params.videoId, res)) return |
44 | if (!await isVideoCaptionExist(res.locals.video, req.params.captionLanguage, res)) return | 44 | if (!await doesVideoCaptionExist(res.locals.video, req.params.captionLanguage, res)) return |
45 | 45 | ||
46 | // Check if the user who did the request is able to update the video | 46 | // Check if the user who did the request is able to update the video |
47 | const user = res.locals.oauth.token.User | 47 | const user = res.locals.oauth.token.User |
@@ -58,7 +58,7 @@ const listVideoCaptionsValidator = [ | |||
58 | logger.debug('Checking listVideoCaptions parameters', { parameters: req.params }) | 58 | logger.debug('Checking listVideoCaptions parameters', { parameters: req.params }) |
59 | 59 | ||
60 | if (areValidationErrors(req, res)) return | 60 | if (areValidationErrors(req, res)) return |
61 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 61 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return |
62 | 62 | ||
63 | return next() | 63 | return next() |
64 | } | 64 | } |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index c2763ce51..e2067c4d9 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -1,12 +1,12 @@ | |||
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 { isAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts' | 4 | import { doesAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts' |
5 | import { | 5 | import { |
6 | isLocalVideoChannelNameExist, | 6 | doesLocalVideoChannelNameExist, |
7 | isVideoChannelDescriptionValid, | 7 | isVideoChannelDescriptionValid, |
8 | isVideoChannelNameValid, | 8 | isVideoChannelNameValid, |
9 | isVideoChannelNameWithHostExist, | 9 | doesVideoChannelNameWithHostExist, |
10 | isVideoChannelSupportValid | 10 | isVideoChannelSupportValid |
11 | } from '../../../helpers/custom-validators/video-channels' | 11 | } from '../../../helpers/custom-validators/video-channels' |
12 | import { logger } from '../../../helpers/logger' | 12 | import { logger } from '../../../helpers/logger' |
@@ -49,7 +49,7 @@ const videoChannelsUpdateValidator = [ | |||
49 | logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) | 49 | logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) |
50 | 50 | ||
51 | if (areValidationErrors(req, res)) return | 51 | if (areValidationErrors(req, res)) return |
52 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return | 52 | if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
53 | 53 | ||
54 | // We need to make additional checks | 54 | // We need to make additional checks |
55 | if (res.locals.videoChannel.Actor.isOwned() === false) { | 55 | if (res.locals.videoChannel.Actor.isOwned() === false) { |
@@ -75,7 +75,7 @@ const videoChannelsRemoveValidator = [ | |||
75 | logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) | 75 | logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) |
76 | 76 | ||
77 | if (areValidationErrors(req, res)) return | 77 | if (areValidationErrors(req, res)) return |
78 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return | 78 | if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
79 | 79 | ||
80 | if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return | 80 | if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return |
81 | if (!await checkVideoChannelIsNotTheLastOne(res)) return | 81 | if (!await checkVideoChannelIsNotTheLastOne(res)) return |
@@ -92,7 +92,7 @@ const videoChannelsNameWithHostValidator = [ | |||
92 | 92 | ||
93 | if (areValidationErrors(req, res)) return | 93 | if (areValidationErrors(req, res)) return |
94 | 94 | ||
95 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return | 95 | if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
96 | 96 | ||
97 | return next() | 97 | return next() |
98 | } | 98 | } |
@@ -105,7 +105,7 @@ const localVideoChannelValidator = [ | |||
105 | logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) | 105 | logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) |
106 | 106 | ||
107 | if (areValidationErrors(req, res)) return | 107 | if (areValidationErrors(req, res)) return |
108 | if (!await isLocalVideoChannelNameExist(req.params.name, res)) return | 108 | if (!await doesLocalVideoChannelNameExist(req.params.name, res)) return |
109 | 109 | ||
110 | return next() | 110 | return next() |
111 | } | 111 | } |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 348d33082..ffde208b7 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -3,7 +3,7 @@ import { body, param } from 'express-validator/check' | |||
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' | 5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
6 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 6 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
8 | import { UserModel } from '../../../models/account/user' | 8 | import { UserModel } from '../../../models/account/user' |
9 | import { VideoModel } from '../../../models/video/video' | 9 | import { VideoModel } from '../../../models/video/video' |
@@ -17,7 +17,7 @@ const listVideoCommentThreadsValidator = [ | |||
17 | logger.debug('Checking listVideoCommentThreads parameters.', { parameters: req.params }) | 17 | logger.debug('Checking listVideoCommentThreads parameters.', { parameters: req.params }) |
18 | 18 | ||
19 | if (areValidationErrors(req, res)) return | 19 | if (areValidationErrors(req, res)) return |
20 | if (!await isVideoExist(req.params.videoId, res, 'only-video')) return | 20 | if (!await doesVideoExist(req.params.videoId, res, 'only-video')) return |
21 | 21 | ||
22 | return next() | 22 | return next() |
23 | } | 23 | } |
@@ -31,8 +31,8 @@ const listVideoThreadCommentsValidator = [ | |||
31 | logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) | 31 | logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) |
32 | 32 | ||
33 | if (areValidationErrors(req, res)) return | 33 | if (areValidationErrors(req, res)) return |
34 | if (!await isVideoExist(req.params.videoId, res, 'only-video')) return | 34 | if (!await doesVideoExist(req.params.videoId, res, 'only-video')) return |
35 | if (!await isVideoCommentThreadExist(req.params.threadId, res.locals.video, res)) return | 35 | if (!await doesVideoCommentThreadExist(req.params.threadId, res.locals.video, res)) return |
36 | 36 | ||
37 | return next() | 37 | return next() |
38 | } | 38 | } |
@@ -46,7 +46,7 @@ const addVideoCommentThreadValidator = [ | |||
46 | logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) | 46 | logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) |
47 | 47 | ||
48 | if (areValidationErrors(req, res)) return | 48 | if (areValidationErrors(req, res)) return |
49 | if (!await isVideoExist(req.params.videoId, res)) return | 49 | if (!await doesVideoExist(req.params.videoId, res)) return |
50 | if (!isVideoCommentsEnabled(res.locals.video, res)) return | 50 | if (!isVideoCommentsEnabled(res.locals.video, res)) return |
51 | 51 | ||
52 | return next() | 52 | return next() |
@@ -62,9 +62,9 @@ const addVideoCommentReplyValidator = [ | |||
62 | logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) | 62 | logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) |
63 | 63 | ||
64 | if (areValidationErrors(req, res)) return | 64 | if (areValidationErrors(req, res)) return |
65 | if (!await isVideoExist(req.params.videoId, res)) return | 65 | if (!await doesVideoExist(req.params.videoId, res)) return |
66 | if (!isVideoCommentsEnabled(res.locals.video, res)) return | 66 | if (!isVideoCommentsEnabled(res.locals.video, res)) return |
67 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | 67 | if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return |
68 | 68 | ||
69 | return next() | 69 | return next() |
70 | } | 70 | } |
@@ -78,8 +78,8 @@ const videoCommentGetValidator = [ | |||
78 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) | 78 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) |
79 | 79 | ||
80 | if (areValidationErrors(req, res)) return | 80 | if (areValidationErrors(req, res)) return |
81 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 81 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return |
82 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | 82 | if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return |
83 | 83 | ||
84 | return next() | 84 | return next() |
85 | } | 85 | } |
@@ -93,8 +93,8 @@ const removeVideoCommentValidator = [ | |||
93 | logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) | 93 | logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) |
94 | 94 | ||
95 | if (areValidationErrors(req, res)) return | 95 | if (areValidationErrors(req, res)) return |
96 | if (!await isVideoExist(req.params.videoId, res)) return | 96 | if (!await doesVideoExist(req.params.videoId, res)) return |
97 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | 97 | if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return |
98 | 98 | ||
99 | // Check if the user who did the request is able to delete the video | 99 | // Check if the user who did the request is able to delete the video |
100 | if (!checkUserCanDeleteVideoComment(res.locals.oauth.token.User, res.locals.videoComment, res)) return | 100 | if (!checkUserCanDeleteVideoComment(res.locals.oauth.token.User, res.locals.videoComment, res)) return |
@@ -116,7 +116,7 @@ export { | |||
116 | 116 | ||
117 | // --------------------------------------------------------------------------- | 117 | // --------------------------------------------------------------------------- |
118 | 118 | ||
119 | async function isVideoCommentThreadExist (id: number, video: VideoModel, res: express.Response) { | 119 | async function doesVideoCommentThreadExist (id: number, video: VideoModel, res: express.Response) { |
120 | const videoComment = await VideoCommentModel.loadById(id) | 120 | const videoComment = await VideoCommentModel.loadById(id) |
121 | 121 | ||
122 | if (!videoComment) { | 122 | if (!videoComment) { |
@@ -147,7 +147,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex | |||
147 | return true | 147 | return true |
148 | } | 148 | } |
149 | 149 | ||
150 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { | 150 | async function doesVideoCommentExist (id: number, video: VideoModel, res: express.Response) { |
151 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) | 151 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) |
152 | 152 | ||
153 | if (!videoComment) { | 153 | if (!videoComment) { |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 121df36b6..3d662b20f 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -6,7 +6,7 @@ import { areValidationErrors } from '../utils' | |||
6 | import { getCommonVideoEditAttributes } from './videos' | 6 | import { getCommonVideoEditAttributes } from './videos' |
7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' | 7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' |
8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
9 | import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' | 9 | import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' |
10 | import { CONFIG } from '../../../initializers/constants' | 10 | import { CONFIG } from '../../../initializers/constants' |
11 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 11 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
12 | 12 | ||
@@ -51,7 +51,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
51 | .end() | 51 | .end() |
52 | } | 52 | } |
53 | 53 | ||
54 | if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) | 54 | if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
55 | 55 | ||
56 | // Check we have at least 1 required param | 56 | // Check we have at least 1 required param |
57 | if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { | 57 | if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 5f33e2d49..4bc79f433 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -4,12 +4,12 @@ import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../.. | |||
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { UserModel } from '../../../models/account/user' | 5 | import { UserModel } from '../../../models/account/user' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { isVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' | 7 | import { doesVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' |
8 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 8 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' | 9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' |
10 | import { | 10 | import { |
11 | isVideoPlaylistDescriptionValid, | 11 | isVideoPlaylistDescriptionValid, |
12 | isVideoPlaylistExist, | 12 | doesVideoPlaylistExist, |
13 | isVideoPlaylistNameValid, | 13 | isVideoPlaylistNameValid, |
14 | isVideoPlaylistPrivacyValid, | 14 | isVideoPlaylistPrivacyValid, |
15 | isVideoPlaylistTimestampValid, | 15 | isVideoPlaylistTimestampValid, |
@@ -17,7 +17,7 @@ import { | |||
17 | } from '../../../helpers/custom-validators/video-playlists' | 17 | } from '../../../helpers/custom-validators/video-playlists' |
18 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 18 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
19 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 19 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
20 | import { isVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' | 20 | import { doesVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' |
21 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' | 21 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' |
22 | import { VideoModel } from '../../../models/video/video' | 22 | import { VideoModel } from '../../../models/video/video' |
23 | import { authenticatePromiseIfNeeded } from '../../oauth' | 23 | import { authenticatePromiseIfNeeded } from '../../oauth' |
@@ -31,7 +31,7 @@ const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ | |||
31 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | 31 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
32 | 32 | ||
33 | const body: VideoPlaylistCreate = req.body | 33 | const body: VideoPlaylistCreate = req.body |
34 | if (body.videoChannelId && !await isVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) | 34 | if (body.videoChannelId && !await doesVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) |
35 | 35 | ||
36 | if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) { | 36 | if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) { |
37 | cleanUpReqFiles(req) | 37 | cleanUpReqFiles(req) |
@@ -52,7 +52,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ | |||
52 | 52 | ||
53 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | 53 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
54 | 54 | ||
55 | if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return cleanUpReqFiles(req) | 55 | if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return cleanUpReqFiles(req) |
56 | 56 | ||
57 | const videoPlaylist = res.locals.videoPlaylist | 57 | const videoPlaylist = res.locals.videoPlaylist |
58 | 58 | ||
@@ -86,7 +86,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ | |||
86 | .json({ error: 'Cannot update a watch later playlist.' }) | 86 | .json({ error: 'Cannot update a watch later playlist.' }) |
87 | } | 87 | } |
88 | 88 | ||
89 | if (body.videoChannelId && !await isVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) | 89 | if (body.videoChannelId && !await doesVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) |
90 | 90 | ||
91 | return next() | 91 | return next() |
92 | } | 92 | } |
@@ -101,7 +101,7 @@ const videoPlaylistsDeleteValidator = [ | |||
101 | 101 | ||
102 | if (areValidationErrors(req, res)) return | 102 | if (areValidationErrors(req, res)) return |
103 | 103 | ||
104 | if (!await isVideoPlaylistExist(req.params.playlistId, res)) return | 104 | if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return |
105 | 105 | ||
106 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 106 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist |
107 | if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { | 107 | if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { |
@@ -126,7 +126,7 @@ const videoPlaylistsGetValidator = [ | |||
126 | 126 | ||
127 | if (areValidationErrors(req, res)) return | 127 | if (areValidationErrors(req, res)) return |
128 | 128 | ||
129 | if (!await isVideoPlaylistExist(req.params.playlistId, res)) return | 129 | if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return |
130 | 130 | ||
131 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 131 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist |
132 | 132 | ||
@@ -174,8 +174,8 @@ const videoPlaylistsAddVideoValidator = [ | |||
174 | 174 | ||
175 | if (areValidationErrors(req, res)) return | 175 | if (areValidationErrors(req, res)) return |
176 | 176 | ||
177 | if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return | 177 | if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return |
178 | if (!await isVideoExist(req.body.videoId, res, 'only-video')) return | 178 | if (!await doesVideoExist(req.body.videoId, res, 'only-video')) return |
179 | 179 | ||
180 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 180 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist |
181 | const video: VideoModel = res.locals.video | 181 | const video: VideoModel = res.locals.video |
@@ -214,8 +214,8 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ | |||
214 | 214 | ||
215 | if (areValidationErrors(req, res)) return | 215 | if (areValidationErrors(req, res)) return |
216 | 216 | ||
217 | if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return | 217 | if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return |
218 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 218 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return |
219 | 219 | ||
220 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 220 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist |
221 | const video: VideoModel = res.locals.video | 221 | const video: VideoModel = res.locals.video |
@@ -282,7 +282,7 @@ const videoPlaylistsReorderVideosValidator = [ | |||
282 | 282 | ||
283 | if (areValidationErrors(req, res)) return | 283 | if (areValidationErrors(req, res)) return |
284 | 284 | ||
285 | if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return | 285 | if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return |
286 | 286 | ||
287 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 287 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist |
288 | if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, videoPlaylist, UserRight.UPDATE_ANY_VIDEO_PLAYLIST, res)) return | 288 | if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, videoPlaylist, UserRight.UPDATE_ANY_VIDEO_PLAYLIST, res)) return |
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 793354520..280385912 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -2,7 +2,7 @@ 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 { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 5 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { areValidationErrors } from '../utils' | 7 | import { areValidationErrors } from '../utils' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
@@ -17,7 +17,7 @@ const videoUpdateRateValidator = [ | |||
17 | logger.debug('Checking videoRate parameters', { parameters: req.body }) | 17 | logger.debug('Checking videoRate parameters', { parameters: req.body }) |
18 | 18 | ||
19 | if (areValidationErrors(req, res)) return | 19 | if (areValidationErrors(req, res)) return |
20 | if (!await isVideoExist(req.params.id, res)) return | 20 | if (!await doesVideoExist(req.params.id, res)) return |
21 | 21 | ||
22 | return next() | 22 | return next() |
23 | } | 23 | } |
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 646d7acb1..f4514f85c 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { param } from 'express-validator/check' | 3 | import { param } from 'express-validator/check' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 5 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { VideoShareModel } from '../../../models/video/video-share' | 7 | import { VideoShareModel } from '../../../models/video/video-share' |
8 | import { areValidationErrors } from '../utils' | 8 | import { areValidationErrors } from '../utils' |
@@ -16,7 +16,7 @@ const videosShareValidator = [ | |||
16 | logger.debug('Checking videoShare parameters', { parameters: req.params }) | 16 | logger.debug('Checking videoShare parameters', { parameters: req.params }) |
17 | 17 | ||
18 | if (areValidationErrors(req, res)) return | 18 | if (areValidationErrors(req, res)) return |
19 | if (!await isVideoExist(req.params.id, res)) return | 19 | if (!await doesVideoExist(req.params.id, res)) return |
20 | 20 | ||
21 | const video: VideoModel = res.locals.video | 21 | const video: VideoModel = res.locals.video |
22 | 22 | ||
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index c38ad8a10..a3b70c0cc 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { body, param } from 'express-validator/check' | 1 | import { body, param } from 'express-validator/check' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 4 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { UserModel } from '../../../models/account/user' | 7 | import { UserModel } from '../../../models/account/user' |
@@ -16,7 +16,7 @@ const videoWatchingValidator = [ | |||
16 | logger.debug('Checking videoWatching parameters', { parameters: req.body }) | 16 | logger.debug('Checking videoWatching parameters', { parameters: req.body }) |
17 | 17 | ||
18 | if (areValidationErrors(req, res)) return | 18 | if (areValidationErrors(req, res)) return |
19 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 19 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return |
20 | 20 | ||
21 | const user = res.locals.oauth.token.User as UserModel | 21 | const user = res.locals.oauth.token.User as UserModel |
22 | if (user.videosHistoryEnabled === false) { | 22 | if (user.videosHistoryEnabled === false) { |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index a5e3ed0dc..92218d4b1 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -17,9 +17,9 @@ import { | |||
17 | isVideoOriginallyPublishedAtValid, | 17 | isVideoOriginallyPublishedAtValid, |
18 | isScheduleVideoUpdatePrivacyValid, | 18 | isScheduleVideoUpdatePrivacyValid, |
19 | isVideoCategoryValid, | 19 | isVideoCategoryValid, |
20 | isVideoChannelOfAccountExist, | 20 | doesVideoChannelOfAccountExist, |
21 | isVideoDescriptionValid, | 21 | isVideoDescriptionValid, |
22 | isVideoExist, | 22 | doesVideoExist, |
23 | isVideoFile, | 23 | isVideoFile, |
24 | isVideoFilterValid, | 24 | isVideoFilterValid, |
25 | isVideoImage, | 25 | isVideoImage, |
@@ -66,7 +66,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
66 | const videoFile: Express.Multer.File = req.files['videofile'][0] | 66 | const videoFile: Express.Multer.File = req.files['videofile'][0] |
67 | const user = res.locals.oauth.token.User | 67 | const user = res.locals.oauth.token.User |
68 | 68 | ||
69 | if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) | 69 | if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
70 | 70 | ||
71 | const isAble = await user.isAbleToUploadVideo(videoFile) | 71 | const isAble = await user.isAbleToUploadVideo(videoFile) |
72 | if (isAble === false) { | 72 | if (isAble === false) { |
@@ -109,7 +109,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
109 | 109 | ||
110 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | 110 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
111 | if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) | 111 | if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) |
112 | if (!await isVideoExist(req.params.id, res)) return cleanUpReqFiles(req) | 112 | if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req) |
113 | 113 | ||
114 | const video = res.locals.video | 114 | const video = res.locals.video |
115 | 115 | ||
@@ -123,7 +123,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
123 | .json({ error: 'Cannot set "private" a video that was not private.' }) | 123 | .json({ error: 'Cannot set "private" a video that was not private.' }) |
124 | } | 124 | } |
125 | 125 | ||
126 | if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) | 126 | if (req.body.channelId && !await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
127 | 127 | ||
128 | return next() | 128 | return next() |
129 | } | 129 | } |
@@ -162,7 +162,7 @@ const videosCustomGetValidator = (fetchType: VideoFetchType) => { | |||
162 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 162 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
163 | 163 | ||
164 | if (areValidationErrors(req, res)) return | 164 | if (areValidationErrors(req, res)) return |
165 | if (!await isVideoExist(req.params.id, res, fetchType)) return | 165 | if (!await doesVideoExist(req.params.id, res, fetchType)) return |
166 | 166 | ||
167 | const video: VideoModel = res.locals.video | 167 | const video: VideoModel = res.locals.video |
168 | 168 | ||
@@ -207,7 +207,7 @@ const videosRemoveValidator = [ | |||
207 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 207 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
208 | 208 | ||
209 | if (areValidationErrors(req, res)) return | 209 | if (areValidationErrors(req, res)) return |
210 | if (!await isVideoExist(req.params.id, res)) return | 210 | if (!await doesVideoExist(req.params.id, res)) return |
211 | 211 | ||
212 | // Check if the user who did the request is able to delete the video | 212 | // Check if the user who did the request is able to delete the video |
213 | if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.REMOVE_ANY_VIDEO, res)) return | 213 | if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.REMOVE_ANY_VIDEO, res)) return |
@@ -223,7 +223,7 @@ const videosChangeOwnershipValidator = [ | |||
223 | logger.debug('Checking changeOwnership parameters', { parameters: req.params }) | 223 | logger.debug('Checking changeOwnership parameters', { parameters: req.params }) |
224 | 224 | ||
225 | if (areValidationErrors(req, res)) return | 225 | if (areValidationErrors(req, res)) return |
226 | if (!await isVideoExist(req.params.videoId, res)) return | 226 | if (!await doesVideoExist(req.params.videoId, res)) return |
227 | 227 | ||
228 | // Check if the user who did the request is able to change the ownership of the video | 228 | // Check if the user who did the request is able to change the ownership of the video |
229 | if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.CHANGE_VIDEO_OWNERSHIP, res)) return | 229 | if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.CHANGE_VIDEO_OWNERSHIP, res)) return |
@@ -272,7 +272,7 @@ const videosTerminateChangeOwnershipValidator = [ | |||
272 | const videosAcceptChangeOwnershipValidator = [ | 272 | const videosAcceptChangeOwnershipValidator = [ |
273 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 273 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
274 | const body = req.body as VideoChangeOwnershipAccept | 274 | const body = req.body as VideoChangeOwnershipAccept |
275 | if (!await isVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return | 275 | if (!await doesVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return |
276 | 276 | ||
277 | const user = res.locals.oauth.token.User | 277 | const user = res.locals.oauth.token.User |
278 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | 278 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel |