aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts2
-rw-r--r--server/helpers/custom-validators/accounts.ts21
-rw-r--r--server/helpers/custom-validators/video-abuses.ts4
-rw-r--r--server/helpers/custom-validators/video-blacklist.ts4
-rw-r--r--server/helpers/custom-validators/video-captions.ts4
-rw-r--r--server/helpers/custom-validators/video-channels.ts12
-rw-r--r--server/helpers/custom-validators/video-imports.ts4
-rw-r--r--server/helpers/custom-validators/video-playlists.ts4
-rw-r--r--server/helpers/custom-validators/videos.ts8
-rw-r--r--server/lib/redis.ts4
-rw-r--r--server/middlewares/validators/account.ts6
-rw-r--r--server/middlewares/validators/blocklist.ts20
-rw-r--r--server/middlewares/validators/feeds.ts16
-rw-r--r--server/middlewares/validators/oembed.ts4
-rw-r--r--server/middlewares/validators/redundancy.ts6
-rw-r--r--server/middlewares/validators/server.ts2
-rw-r--r--server/middlewares/validators/users.ts4
-rw-r--r--server/middlewares/validators/videos/video-abuses.ts14
-rw-r--r--server/middlewares/validators/videos/video-blacklist.ts14
-rw-r--r--server/middlewares/validators/videos/video-captions.ts12
-rw-r--r--server/middlewares/validators/videos/video-channels.ts14
-rw-r--r--server/middlewares/validators/videos/video-comments.ts26
-rw-r--r--server/middlewares/validators/videos/video-imports.ts4
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts26
-rw-r--r--server/middlewares/validators/videos/video-rates.ts4
-rw-r--r--server/middlewares/validators/videos/video-shares.ts4
-rw-r--r--server/middlewares/validators/videos/video-watch.ts4
-rw-r--r--server/middlewares/validators/videos/videos.ts18
28 files changed, 132 insertions, 133 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 6ac13e6a4..27f67895e 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -421,7 +421,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
421 const videoInstance = res.locals.video 421 const videoInstance = res.locals.video
422 422
423 const ip = req.ip 423 const ip = req.ip
424 const exists = await Redis.Instance.isVideoIPViewExists(ip, videoInstance.uuid) 424 const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid)
425 if (exists) { 425 if (exists) {
426 logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid) 426 logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid)
427 return res.status(204).end() 427 return res.status(204).end()
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index aad04fe93..146c7708e 100644
--- a/server/helpers/custom-validators/accounts.ts
+++ b/server/helpers/custom-validators/accounts.ts
@@ -5,7 +5,6 @@ import * as validator from 'validator'
5import { AccountModel } from '../../models/account/account' 5import { AccountModel } from '../../models/account/account'
6import { isUserDescriptionValid, isUserUsernameValid } from './users' 6import { isUserDescriptionValid, isUserUsernameValid } from './users'
7import { exists } from './misc' 7import { exists } from './misc'
8import { CONFIG } from '../../initializers'
9 8
10function isAccountNameValid (value: string) { 9function isAccountNameValid (value: string) {
11 return isUserUsernameValid(value) 10 return isUserUsernameValid(value)
@@ -19,7 +18,7 @@ function isAccountDescriptionValid (value: string) {
19 return isUserDescriptionValid(value) 18 return isUserDescriptionValid(value)
20} 19}
21 20
22function isAccountIdExist (id: number | string, res: Response, sendNotFound = true) { 21function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
23 let promise: Bluebird<AccountModel> 22 let promise: Bluebird<AccountModel>
24 23
25 if (validator.isInt('' + id)) { 24 if (validator.isInt('' + id)) {
@@ -28,20 +27,20 @@ function isAccountIdExist (id: number | string, res: Response, sendNotFound = tr
28 promise = AccountModel.loadByUUID('' + id) 27 promise = AccountModel.loadByUUID('' + id)
29 } 28 }
30 29
31 return isAccountExist(promise, res, sendNotFound) 30 return doesAccountExist(promise, res, sendNotFound)
32} 31}
33 32
34function isLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { 33function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) {
35 const promise = AccountModel.loadLocalByName(name) 34 const promise = AccountModel.loadLocalByName(name)
36 35
37 return isAccountExist(promise, res, sendNotFound) 36 return doesAccountExist(promise, res, sendNotFound)
38} 37}
39 38
40function isAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { 39function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) {
41 return isAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) 40 return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound)
42} 41}
43 42
44async function isAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { 43async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) {
45 const account = await p 44 const account = await p
46 45
47 if (!account) { 46 if (!account) {
@@ -63,9 +62,9 @@ async function isAccountExist (p: Bluebird<AccountModel>, res: Response, sendNot
63 62
64export { 63export {
65 isAccountIdValid, 64 isAccountIdValid,
66 isAccountIdExist, 65 doesAccountIdExist,
67 isLocalAccountNameExist, 66 doesLocalAccountNameExist,
68 isAccountDescriptionValid, 67 isAccountDescriptionValid,
69 isAccountNameWithHostExist, 68 doesAccountNameWithHostExist,
70 isAccountNameValid 69 isAccountNameValid
71} 70}
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts
index 290efb149..71500fde5 100644
--- a/server/helpers/custom-validators/video-abuses.ts
+++ b/server/helpers/custom-validators/video-abuses.ts
@@ -18,7 +18,7 @@ function isVideoAbuseStateValid (value: string) {
18 return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined 18 return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined
19} 19}
20 20
21async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) { 21async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) {
22 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) 22 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId)
23 23
24 if (videoAbuse === null) { 24 if (videoAbuse === null) {
@@ -36,7 +36,7 @@ async function isVideoAbuseExist (abuseId: number, videoId: number, res: Respons
36// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
37 37
38export { 38export {
39 isVideoAbuseExist, 39 doesVideoAbuseExist,
40 isVideoAbuseStateValid, 40 isVideoAbuseStateValid,
41 isVideoAbuseReasonValid, 41 isVideoAbuseReasonValid,
42 isVideoAbuseModerationCommentValid 42 isVideoAbuseModerationCommentValid
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts
index b36b08d8b..25f908228 100644
--- a/server/helpers/custom-validators/video-blacklist.ts
+++ b/server/helpers/custom-validators/video-blacklist.ts
@@ -9,7 +9,7 @@ function isVideoBlacklistReasonValid (value: string) {
9 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) 9 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
10} 10}
11 11
12async function isVideoBlacklistExist (videoId: number, res: Response) { 12async function doesVideoBlacklistExist (videoId: number, res: Response) {
13 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) 13 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
14 14
15 if (videoBlacklist === null) { 15 if (videoBlacklist === null) {
@@ -28,5 +28,5 @@ async function isVideoBlacklistExist (videoId: number, res: Response) {
28 28
29export { 29export {
30 isVideoBlacklistReasonValid, 30 isVideoBlacklistReasonValid,
31 isVideoBlacklistExist 31 doesVideoBlacklistExist
32} 32}
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts
index b33d90e18..8bd139003 100644
--- a/server/helpers/custom-validators/video-captions.ts
+++ b/server/helpers/custom-validators/video-captions.ts
@@ -16,7 +16,7 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File
16 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) 16 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
17} 17}
18 18
19async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) { 19async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) {
20 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) 20 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
21 21
22 if (!videoCaption) { 22 if (!videoCaption) {
@@ -36,5 +36,5 @@ async function isVideoCaptionExist (video: VideoModel, language: string, res: Re
36export { 36export {
37 isVideoCaptionFile, 37 isVideoCaptionFile,
38 isVideoCaptionLanguageValid, 38 isVideoCaptionLanguageValid,
39 isVideoCaptionExist 39 doesVideoCaptionExist
40} 40}
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index 3792bbdcc..fad7a9bcf 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -20,13 +20,13 @@ function isVideoChannelSupportValid (value: string) {
20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) 20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
21} 21}
22 22
23async function isLocalVideoChannelNameExist (name: string, res: express.Response) { 23async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
24 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) 24 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
25 25
26 return processVideoChannelExist(videoChannel, res) 26 return processVideoChannelExist(videoChannel, res)
27} 27}
28 28
29async function isVideoChannelIdExist (id: number | string, res: express.Response) { 29async function doesVideoChannelIdExist (id: number | string, res: express.Response) {
30 let videoChannel: VideoChannelModel 30 let videoChannel: VideoChannelModel
31 if (validator.isInt('' + id)) { 31 if (validator.isInt('' + id)) {
32 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) 32 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
@@ -37,7 +37,7 @@ async function isVideoChannelIdExist (id: number | string, res: express.Response
37 return processVideoChannelExist(videoChannel, res) 37 return processVideoChannelExist(videoChannel, res)
38} 38}
39 39
40async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { 40async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
41 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) 41 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
42 42
43 return processVideoChannelExist(videoChannel, res) 43 return processVideoChannelExist(videoChannel, res)
@@ -46,12 +46,12 @@ async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: exp
46// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
47 47
48export { 48export {
49 isVideoChannelNameWithHostExist, 49 doesVideoChannelNameWithHostExist,
50 isLocalVideoChannelNameExist, 50 doesLocalVideoChannelNameExist,
51 isVideoChannelDescriptionValid, 51 isVideoChannelDescriptionValid,
52 isVideoChannelNameValid, 52 isVideoChannelNameValid,
53 isVideoChannelSupportValid, 53 isVideoChannelSupportValid,
54 isVideoChannelIdExist 54 doesVideoChannelIdExist
55} 55}
56 56
57function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { 57function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index ce9e9193c..14db9b534 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -30,7 +30,7 @@ function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multe
30 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) 30 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true)
31} 31}
32 32
33async function isVideoImportExist (id: number, res: express.Response) { 33async function doesVideoImportExist (id: number, res: express.Response) {
34 const videoImport = await VideoImportModel.loadAndPopulateVideo(id) 34 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
35 35
36 if (!videoImport) { 36 if (!videoImport) {
@@ -50,6 +50,6 @@ async function isVideoImportExist (id: number, res: express.Response) {
50export { 50export {
51 isVideoImportStateValid, 51 isVideoImportStateValid,
52 isVideoImportTargetUrlValid, 52 isVideoImportTargetUrlValid,
53 isVideoImportExist, 53 doesVideoImportExist,
54 isVideoImportTorrentFile 54 isVideoImportTorrentFile
55} 55}
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts
index e0eb423d7..c962c5532 100644
--- a/server/helpers/custom-validators/video-playlists.ts
+++ b/server/helpers/custom-validators/video-playlists.ts
@@ -26,7 +26,7 @@ function isVideoPlaylistTypeValid (value: any) {
26 return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined 26 return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined
27} 27}
28 28
29async function isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { 29async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') {
30 const videoPlaylist = fetchType === 'summary' 30 const videoPlaylist = fetchType === 'summary'
31 ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) 31 ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
32 : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) 32 : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
@@ -46,7 +46,7 @@ async function isVideoPlaylistExist (id: number | string, res: express.Response,
46// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
47 47
48export { 48export {
49 isVideoPlaylistExist, 49 doesVideoPlaylistExist,
50 isVideoPlaylistNameValid, 50 isVideoPlaylistNameValid,
51 isVideoPlaylistDescriptionValid, 51 isVideoPlaylistDescriptionValid,
52 isVideoPlaylistPrivacyValid, 52 isVideoPlaylistPrivacyValid,
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index d00d24c4c..dd9d62d24 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -165,7 +165,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use
165 return true 165 return true
166} 166}
167 167
168async function isVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { 168async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
169 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 169 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
170 170
171 const video = await fetchVideo(id, fetchType, userId) 171 const video = await fetchVideo(id, fetchType, userId)
@@ -182,7 +182,7 @@ async function isVideoExist (id: number | string, res: Response, fetchType: Vide
182 return true 182 return true
183} 183}
184 184
185async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { 185async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
186 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { 186 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
187 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) 187 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
188 if (videoChannel === null) { 188 if (videoChannel === null) {
@@ -236,9 +236,9 @@ export {
236 isVideoPrivacyValid, 236 isVideoPrivacyValid,
237 isVideoFileResolutionValid, 237 isVideoFileResolutionValid,
238 isVideoFileSizeValid, 238 isVideoFileSizeValid,
239 isVideoExist, 239 doesVideoExist,
240 isVideoImage, 240 isVideoImage,
241 isVideoChannelOfAccountExist, 241 doesVideoChannelOfAccountExist,
242 isVideoSupportValid, 242 isVideoSupportValid,
243 isVideoFilterValid 243 isVideoFilterValid
244} 244}
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 3628c0583..d85dbe2b5 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -88,7 +88,7 @@ class Redis {
88 return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) 88 return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME)
89 } 89 }
90 90
91 async isContactFormIpExists (ip: string) { 91 async doesContactFormIpExist (ip: string) {
92 return this.exists(this.generateContactFormKey(ip)) 92 return this.exists(this.generateContactFormKey(ip))
93 } 93 }
94 94
@@ -98,7 +98,7 @@ class Redis {
98 return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME) 98 return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME)
99 } 99 }
100 100
101 async isVideoIPViewExists (ip: string, videoUUID: string) { 101 async doesVideoIPViewExist (ip: string, videoUUID: string) {
102 return this.exists(this.generateViewKey(ip, videoUUID)) 102 return this.exists(this.generateViewKey(ip, videoUUID))
103 } 103 }
104 104
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { isAccountNameValid, isAccountNameWithHostExist, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' 3import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { 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'
2import * as express from 'express' 2import * as express from 'express'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' 5import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
6import { UserModel } from '../../models/account/user' 6import { UserModel } from '../../models/account/user'
7import { AccountBlocklistModel } from '../../models/account/account-blocklist' 7import { AccountBlocklistModel } from '../../models/account/account-blocklist'
8import { isHostValid } from '../../helpers/custom-validators/servers' 8import { 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
144async function isUnblockAccountExists (accountId: number, targetAccountId: number, res: express.Response) { 144async 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
159async function isUnblockServerExists (accountId: number, host: string, res: express.Response) { 159async 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param, query } from 'express-validator/check' 2import { param, query } from 'express-validator/check'
3import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' 3import { doesAccountIdExist, isAccountNameValid, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './utils' 6import { areValidationErrors } from './utils'
7import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' 7import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
8import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' 8import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels'
9import { isVideoExist } from '../../helpers/custom-validators/videos' 9import { doesVideoExist } from '../../helpers/custom-validators/videos'
10import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' 10import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
11 11
12const videoFeedsValidator = [ 12const 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'
3import { join } from 'path' 3import { join } from 'path'
4import { isTestInstance } from '../../helpers/core-utils' 4import { isTestInstance } from '../../helpers/core-utils'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 6import { doesVideoExist } from '../../helpers/custom-validators/videos'
7import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
8import { CONFIG } from '../../initializers' 8import { CONFIG } from '../../initializers'
9import { areValidationErrors } from './utils' 9import { 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'
2import 'express-validator' 2import 'express-validator'
3import { param, body } from 'express-validator/check' 3import { param, body } from 'express-validator/check'
4import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' 4import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../helpers/custom-validators/videos' 5import { doesVideoExist } from '../../helpers/custom-validators/videos'
6import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './utils' 7import { areValidationErrors } from './utils'
8import { VideoModel } from '../../models/video/video' 8import { 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'
19import { isVideoExist } from '../../helpers/custom-validators/videos' 19import { doesVideoExist } from '../../helpers/custom-validators/videos'
20import { logger } from '../../helpers/logger' 20import { logger } from '../../helpers/logger'
21import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 21import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
22import { Redis } from '../../lib/redis' 22import { 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'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../../helpers/custom-validators/videos' 5import { doesVideoExist } from '../../../helpers/custom-validators/videos'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { areValidationErrors } from '../utils' 7import { areValidationErrors } from '../utils'
8import { 8import {
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4import { isVideoExist } from '../../../helpers/custom-validators/videos' 4import { doesVideoExist } from '../../../helpers/custom-validators/videos'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
7import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' 7import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
8import { VideoModel } from '../../../models/video/video' 8import { VideoModel } from '../../../models/video/video'
9 9
10const videosBlacklistRemoveValidator = [ 10const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from '../utils' 2import { areValidationErrors } from '../utils'
3import { checkUserCanManageVideo, isVideoExist } from '../../../helpers/custom-validators/videos' 3import { checkUserCanManageVideo, doesVideoExist } from '../../../helpers/custom-validators/videos'
4import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
5import { body, param } from 'express-validator/check' 5import { body, param } from 'express-validator/check'
6import { CONSTRAINTS_FIELDS } from '../../../initializers' 6import { CONSTRAINTS_FIELDS } from '../../../initializers'
7import { UserRight } from '../../../../shared' 7import { UserRight } from '../../../../shared'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
9import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' 9import { doesVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions'
10import { cleanUpReqFiles } from '../../../helpers/express-utils' 10import { cleanUpReqFiles } from '../../../helpers/express-utils'
11 11
12const addVideoCaptionValidator = [ 12const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { isAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts' 4import { doesAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts'
5import { 5import {
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'
12import { logger } from '../../../helpers/logger' 12import { 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'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' 5import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments'
6import { isVideoExist } from '../../../helpers/custom-validators/videos' 6import { doesVideoExist } from '../../../helpers/custom-validators/videos'
7import { logger } from '../../../helpers/logger' 7import { logger } from '../../../helpers/logger'
8import { UserModel } from '../../../models/account/user' 8import { UserModel } from '../../../models/account/user'
9import { VideoModel } from '../../../models/video/video' 9import { 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
119async function isVideoCommentThreadExist (id: number, video: VideoModel, res: express.Response) { 119async 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
150async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { 150async 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'
6import { getCommonVideoEditAttributes } from './videos' 6import { getCommonVideoEditAttributes } from './videos'
7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../../helpers/express-utils' 8import { cleanUpReqFiles } from '../../../helpers/express-utils'
9import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' 9import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
10import { CONFIG } from '../../../initializers/constants' 10import { CONFIG } from '../../../initializers/constants'
11import { CONSTRAINTS_FIELDS } from '../../../initializers' 11import { 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 '../../../..
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { UserModel } from '../../../models/account/user' 5import { UserModel } from '../../../models/account/user'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
7import { isVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' 7import { doesVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos'
8import { CONSTRAINTS_FIELDS } from '../../../initializers' 8import { CONSTRAINTS_FIELDS } from '../../../initializers'
9import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' 9import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc'
10import { 10import {
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'
18import { VideoPlaylistModel } from '../../../models/video/video-playlist' 18import { VideoPlaylistModel } from '../../../models/video/video-playlist'
19import { cleanUpReqFiles } from '../../../helpers/express-utils' 19import { cleanUpReqFiles } from '../../../helpers/express-utils'
20import { isVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' 20import { doesVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels'
21import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' 21import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element'
22import { VideoModel } from '../../../models/video/video' 22import { VideoModel } from '../../../models/video/video'
23import { authenticatePromiseIfNeeded } from '../../oauth' 23import { 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'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' 5import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { areValidationErrors } from '../utils' 7import { areValidationErrors } from '../utils'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 8import { 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'
2import 'express-validator' 2import 'express-validator'
3import { param } from 'express-validator/check' 3import { param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../../helpers/custom-validators/videos' 5import { doesVideoExist } from '../../../helpers/custom-validators/videos'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { VideoShareModel } from '../../../models/video/video-share' 7import { VideoShareModel } from '../../../models/video/video-share'
8import { areValidationErrors } from '../utils' 8import { 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 @@
1import { body, param } from 'express-validator/check' 1import { body, param } from 'express-validator/check'
2import * as express from 'express' 2import * as express from 'express'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4import { isVideoExist } from '../../../helpers/custom-validators/videos' 4import { doesVideoExist } from '../../../helpers/custom-validators/videos'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { UserModel } from '../../../models/account/user' 7import { 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 = [
272const videosAcceptChangeOwnershipValidator = [ 272const 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