From 0f6acda11681de90d38dd18669863c6e270851ee Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 09:26:50 +0100 Subject: [PATCH] Does exist --- server/controllers/api/videos/index.ts | 2 +- server/helpers/custom-validators/accounts.ts | 21 +++++++-------- .../helpers/custom-validators/video-abuses.ts | 4 +-- .../custom-validators/video-blacklist.ts | 4 +-- .../custom-validators/video-captions.ts | 4 +-- .../custom-validators/video-channels.ts | 12 ++++----- .../custom-validators/video-imports.ts | 4 +-- .../custom-validators/video-playlists.ts | 4 +-- server/helpers/custom-validators/videos.ts | 8 +++--- server/lib/redis.ts | 4 +-- server/middlewares/validators/account.ts | 6 ++--- server/middlewares/validators/blocklist.ts | 20 +++++++------- server/middlewares/validators/feeds.ts | 16 ++++++------ server/middlewares/validators/oembed.ts | 4 +-- server/middlewares/validators/redundancy.ts | 6 ++--- server/middlewares/validators/server.ts | 2 +- server/middlewares/validators/users.ts | 4 +-- .../validators/videos/video-abuses.ts | 14 +++++----- .../validators/videos/video-blacklist.ts | 14 +++++----- .../validators/videos/video-captions.ts | 12 ++++----- .../validators/videos/video-channels.ts | 14 +++++----- .../validators/videos/video-comments.ts | 26 +++++++++---------- .../validators/videos/video-imports.ts | 4 +-- .../validators/videos/video-playlists.ts | 26 +++++++++---------- .../validators/videos/video-rates.ts | 4 +-- .../validators/videos/video-shares.ts | 4 +-- .../validators/videos/video-watch.ts | 4 +-- .../middlewares/validators/videos/videos.ts | 18 ++++++------- 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) { const videoInstance = res.locals.video const ip = req.ip - const exists = await Redis.Instance.isVideoIPViewExists(ip, videoInstance.uuid) + const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) if (exists) { logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid) 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' import { AccountModel } from '../../models/account/account' import { isUserDescriptionValid, isUserUsernameValid } from './users' import { exists } from './misc' -import { CONFIG } from '../../initializers' function isAccountNameValid (value: string) { return isUserUsernameValid(value) @@ -19,7 +18,7 @@ function isAccountDescriptionValid (value: string) { return isUserDescriptionValid(value) } -function isAccountIdExist (id: number | string, res: Response, sendNotFound = true) { +function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { let promise: Bluebird if (validator.isInt('' + id)) { @@ -28,20 +27,20 @@ function isAccountIdExist (id: number | string, res: Response, sendNotFound = tr promise = AccountModel.loadByUUID('' + id) } - return isAccountExist(promise, res, sendNotFound) + return doesAccountExist(promise, res, sendNotFound) } -function isLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { +function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { const promise = AccountModel.loadLocalByName(name) - return isAccountExist(promise, res, sendNotFound) + return doesAccountExist(promise, res, sendNotFound) } -function isAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { - return isAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) +function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { + return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) } -async function isAccountExist (p: Bluebird, res: Response, sendNotFound: boolean) { +async function doesAccountExist (p: Bluebird, res: Response, sendNotFound: boolean) { const account = await p if (!account) { @@ -63,9 +62,9 @@ async function isAccountExist (p: Bluebird, res: Response, sendNot export { isAccountIdValid, - isAccountIdExist, - isLocalAccountNameExist, + doesAccountIdExist, + doesLocalAccountNameExist, isAccountDescriptionValid, - isAccountNameWithHostExist, + doesAccountNameWithHostExist, isAccountNameValid } 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) { return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined } -async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) { +async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) if (videoAbuse === null) { @@ -36,7 +36,7 @@ async function isVideoAbuseExist (abuseId: number, videoId: number, res: Respons // --------------------------------------------------------------------------- export { - isVideoAbuseExist, + doesVideoAbuseExist, isVideoAbuseStateValid, isVideoAbuseReasonValid, 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) { return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) } -async function isVideoBlacklistExist (videoId: number, res: Response) { +async function doesVideoBlacklistExist (videoId: number, res: Response) { const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) if (videoBlacklist === null) { @@ -28,5 +28,5 @@ async function isVideoBlacklistExist (videoId: number, res: Response) { export { isVideoBlacklistReasonValid, - isVideoBlacklistExist + doesVideoBlacklistExist } 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 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) } -async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) { +async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) if (!videoCaption) { @@ -36,5 +36,5 @@ async function isVideoCaptionExist (video: VideoModel, language: string, res: Re export { isVideoCaptionFile, isVideoCaptionLanguageValid, - isVideoCaptionExist + doesVideoCaptionExist } 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) { return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) } -async function isLocalVideoChannelNameExist (name: string, res: express.Response) { +async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) return processVideoChannelExist(videoChannel, res) } -async function isVideoChannelIdExist (id: number | string, res: express.Response) { +async function doesVideoChannelIdExist (id: number | string, res: express.Response) { let videoChannel: VideoChannelModel if (validator.isInt('' + id)) { videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) @@ -37,7 +37,7 @@ async function isVideoChannelIdExist (id: number | string, res: express.Response return processVideoChannelExist(videoChannel, res) } -async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { +async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) return processVideoChannelExist(videoChannel, res) @@ -46,12 +46,12 @@ async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: exp // --------------------------------------------------------------------------- export { - isVideoChannelNameWithHostExist, - isLocalVideoChannelNameExist, + doesVideoChannelNameWithHostExist, + doesLocalVideoChannelNameExist, isVideoChannelDescriptionValid, isVideoChannelNameValid, isVideoChannelSupportValid, - isVideoChannelIdExist + doesVideoChannelIdExist } function 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 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) } -async function isVideoImportExist (id: number, res: express.Response) { +async function doesVideoImportExist (id: number, res: express.Response) { const videoImport = await VideoImportModel.loadAndPopulateVideo(id) if (!videoImport) { @@ -50,6 +50,6 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist, + doesVideoImportExist, isVideoImportTorrentFile } 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) { return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined } -async function isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { +async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { const videoPlaylist = fetchType === 'summary' ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) @@ -46,7 +46,7 @@ async function isVideoPlaylistExist (id: number | string, res: express.Response, // --------------------------------------------------------------------------- export { - isVideoPlaylistExist, + doesVideoPlaylistExist, isVideoPlaylistNameValid, isVideoPlaylistDescriptionValid, 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 return true } -async function isVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { +async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined const video = await fetchVideo(id, fetchType, userId) @@ -182,7 +182,7 @@ async function isVideoExist (id: number | string, res: Response, fetchType: Vide return true } -async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { +async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) if (videoChannel === null) { @@ -236,9 +236,9 @@ export { isVideoPrivacyValid, isVideoFileResolutionValid, isVideoFileSizeValid, - isVideoExist, + doesVideoExist, isVideoImage, - isVideoChannelOfAccountExist, + doesVideoChannelOfAccountExist, isVideoSupportValid, isVideoFilterValid } 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 { return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) } - async isContactFormIpExists (ip: string) { + async doesContactFormIpExist (ip: string) { return this.exists(this.generateContactFormKey(ip)) } @@ -98,7 +98,7 @@ class Redis { return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME) } - async isVideoIPViewExists (ip: string, videoUUID: string) { + async doesVideoIPViewExist (ip: string, videoUUID: string) { return this.exists(this.generateViewKey(ip, videoUUID)) } 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 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { isAccountNameValid, isAccountNameWithHostExist, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' +import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' @@ -11,7 +11,7 @@ const localAccountValidator = [ logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isLocalAccountNameExist(req.params.name, res)) return + if (!await doesLocalAccountNameExist(req.params.name, res)) return return next() } @@ -24,7 +24,7 @@ const accountNameWithHostGetValidator = [ logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isAccountNameWithHostExist(req.params.accountName, res)) return + if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return return next() } 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' import * as express from 'express' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' -import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' +import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' import { UserModel } from '../../models/account/user' import { AccountBlocklistModel } from '../../models/account/account-blocklist' import { isHostValid } from '../../helpers/custom-validators/servers' @@ -18,7 +18,7 @@ const blockAccountValidator = [ logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isAccountNameWithHostExist(req.body.accountName, res)) return + if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return const user = res.locals.oauth.token.User as UserModel const accountToBlock = res.locals.account @@ -42,11 +42,11 @@ const unblockAccountByAccountValidator = [ logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isAccountNameWithHostExist(req.params.accountName, res)) return + if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return const user = res.locals.oauth.token.User as UserModel const targetAccount = res.locals.account - if (!await isUnblockAccountExists(user.Account.id, targetAccount.id, res)) return + if (!await doesUnblockAccountExist(user.Account.id, targetAccount.id, res)) return return next() } @@ -59,11 +59,11 @@ const unblockAccountByServerValidator = [ logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isAccountNameWithHostExist(req.params.accountName, res)) return + if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return const serverActor = await getServerActor() const targetAccount = res.locals.account - if (!await isUnblockAccountExists(serverActor.Account.id, targetAccount.id, res)) return + if (!await doesUnblockAccountExist(serverActor.Account.id, targetAccount.id, res)) return return next() } @@ -107,7 +107,7 @@ const unblockServerByAccountValidator = [ if (areValidationErrors(req, res)) return const user = res.locals.oauth.token.User as UserModel - if (!await isUnblockServerExists(user.Account.id, req.params.host, res)) return + if (!await doesUnblockServerExist(user.Account.id, req.params.host, res)) return return next() } @@ -122,7 +122,7 @@ const unblockServerByServerValidator = [ if (areValidationErrors(req, res)) return const serverActor = await getServerActor() - if (!await isUnblockServerExists(serverActor.Account.id, req.params.host, res)) return + if (!await doesUnblockServerExist(serverActor.Account.id, req.params.host, res)) return return next() } @@ -141,7 +141,7 @@ export { // --------------------------------------------------------------------------- -async function isUnblockAccountExists (accountId: number, targetAccountId: number, res: express.Response) { +async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) if (!accountBlock) { res.status(404) @@ -156,7 +156,7 @@ async function isUnblockAccountExists (accountId: number, targetAccountId: numbe return true } -async function isUnblockServerExists (accountId: number, host: string, res: express.Response) { +async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) if (!serverBlock) { 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 @@ import * as express from 'express' import { param, query } from 'express-validator/check' -import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' +import { doesAccountIdExist, isAccountNameValid, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' -import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' -import { isVideoExist } from '../../helpers/custom-validators/videos' +import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' +import { doesVideoExist } from '../../helpers/custom-validators/videos' import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' const videoFeedsValidator = [ @@ -22,10 +22,10 @@ const videoFeedsValidator = [ if (areValidationErrors(req, res)) return - if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return - if (req.query.videoChannelId && !await isVideoChannelIdExist(req.query.videoChannelId, res)) return - if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return - if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return + if (req.query.accountId && !await doesAccountIdExist(req.query.accountId, res)) return + if (req.query.videoChannelId && !await doesVideoChannelIdExist(req.query.videoChannelId, res)) return + if (req.query.accountName && !await doesAccountNameWithHostExist(req.query.accountName, res)) return + if (req.query.videoChannelName && !await doesVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return return next() } @@ -41,7 +41,7 @@ const videoCommentsFeedsValidator = [ if (areValidationErrors(req, res)) return - if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return + if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return return next() } 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' import { join } from 'path' import { isTestInstance } from '../../helpers/core-utils' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' -import { isVideoExist } from '../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../helpers/custom-validators/videos' import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers' import { areValidationErrors } from './utils' @@ -52,7 +52,7 @@ const oembedValidator = [ .end() } - if (!await isVideoExist(videoId, res)) return + if (!await doesVideoExist(videoId, res)) return return next() } 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' import 'express-validator' import { param, body } from 'express-validator/check' import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' -import { isVideoExist } from '../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../helpers/custom-validators/videos' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' import { VideoModel } from '../../models/video/video' @@ -27,7 +27,7 @@ const videoFileRedundancyGetValidator = [ logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return const video: VideoModel = res.locals.video const videoFile = video.VideoFiles.find(f => { @@ -53,7 +53,7 @@ const videoPlaylistRedundancyGetValidator = [ logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return const video: VideoModel = res.locals.video 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 = [ .end() } - if (await Redis.Instance.isContactFormIpExists(req.ip)) { + if (await Redis.Instance.doesContactFormIpExist(req.ip)) { logger.info('Refusing a contact form by %s: already sent one recently.', req.ip) 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 { isUserVideoQuotaDailyValid, isUserVideoQuotaValid, isUserVideosHistoryEnabledValid } from '../../helpers/custom-validators/users' -import { isVideoExist } from '../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../helpers/custom-validators/videos' import { logger } from '../../helpers/logger' import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' import { Redis } from '../../lib/redis' @@ -194,7 +194,7 @@ const usersVideoRatingValidator = [ logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'id')) return + if (!await doesVideoExist(req.params.videoId, res, 'id')) return return next() } 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' import 'express-validator' import { body, param } from 'express-validator/check' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' -import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' import { - isVideoAbuseExist, + doesVideoAbuseExist, isVideoAbuseModerationCommentValid, isVideoAbuseReasonValid, isVideoAbuseStateValid @@ -20,7 +20,7 @@ const videoAbuseReportValidator = [ logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return return next() } @@ -34,8 +34,8 @@ const videoAbuseGetValidator = [ logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return return next() } @@ -55,8 +55,8 @@ const videoAbuseUpdateValidator = [ logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoAbuseExist(req.params.id, res.locals.video.id, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return return next() } 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 @@ import * as express from 'express' import { body, param } from 'express-validator/check' import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' -import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' -import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' +import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' import { VideoModel } from '../../../models/video/video' const videosBlacklistRemoveValidator = [ @@ -14,8 +14,8 @@ const videosBlacklistRemoveValidator = [ logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoBlacklistExist(res.locals.video.id, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return return next() } @@ -35,7 +35,7 @@ const videosBlacklistAddValidator = [ logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return const video: VideoModel = res.locals.video if (req.body.unfederate === true && video.remote === true) { @@ -59,8 +59,8 @@ const videosBlacklistUpdateValidator = [ logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoBlacklistExist(res.locals.video.id, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return return next() } 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 @@ import * as express from 'express' import { areValidationErrors } from '../utils' -import { checkUserCanManageVideo, isVideoExist } from '../../../helpers/custom-validators/videos' +import { checkUserCanManageVideo, doesVideoExist } from '../../../helpers/custom-validators/videos' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' import { body, param } from 'express-validator/check' import { CONSTRAINTS_FIELDS } from '../../../initializers' import { UserRight } from '../../../../shared' import { logger } from '../../../helpers/logger' -import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' +import { doesVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' import { cleanUpReqFiles } from '../../../helpers/express-utils' const addVideoCaptionValidator = [ @@ -22,7 +22,7 @@ const addVideoCaptionValidator = [ logger.debug('Checking addVideoCaption parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return cleanUpReqFiles(req) - if (!await isVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) + if (!await doesVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) // Check if the user who did the request is able to update the video const user = res.locals.oauth.token.User @@ -40,8 +40,8 @@ const deleteVideoCaptionValidator = [ logger.debug('Checking deleteVideoCaption parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoCaptionExist(res.locals.video, req.params.captionLanguage, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoCaptionExist(res.locals.video, req.params.captionLanguage, res)) return // Check if the user who did the request is able to update the video const user = res.locals.oauth.token.User @@ -58,7 +58,7 @@ const listVideoCaptionsValidator = [ logger.debug('Checking listVideoCaptions parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'id')) return + if (!await doesVideoExist(req.params.videoId, res, 'id')) return return next() } 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 @@ import * as express from 'express' import { body, param } from 'express-validator/check' import { UserRight } from '../../../../shared' -import { isAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts' +import { doesAccountNameWithHostExist } from '../../../helpers/custom-validators/accounts' import { - isLocalVideoChannelNameExist, + doesLocalVideoChannelNameExist, isVideoChannelDescriptionValid, isVideoChannelNameValid, - isVideoChannelNameWithHostExist, + doesVideoChannelNameWithHostExist, isVideoChannelSupportValid } from '../../../helpers/custom-validators/video-channels' import { logger } from '../../../helpers/logger' @@ -49,7 +49,7 @@ const videoChannelsUpdateValidator = [ logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return + if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return // We need to make additional checks if (res.locals.videoChannel.Actor.isOwned() === false) { @@ -75,7 +75,7 @@ const videoChannelsRemoveValidator = [ logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return + if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return if (!await checkVideoChannelIsNotTheLastOne(res)) return @@ -92,7 +92,7 @@ const videoChannelsNameWithHostValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return + if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return return next() } @@ -105,7 +105,7 @@ const localVideoChannelValidator = [ logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isLocalVideoChannelNameExist(req.params.name, res)) return + if (!await doesLocalVideoChannelNameExist(req.params.name, res)) return return next() } 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' import { UserRight } from '../../../../shared' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' -import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { UserModel } from '../../../models/account/user' import { VideoModel } from '../../../models/video/video' @@ -17,7 +17,7 @@ const listVideoCommentThreadsValidator = [ logger.debug('Checking listVideoCommentThreads parameters.', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'only-video')) return + if (!await doesVideoExist(req.params.videoId, res, 'only-video')) return return next() } @@ -31,8 +31,8 @@ const listVideoThreadCommentsValidator = [ logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'only-video')) return - if (!await isVideoCommentThreadExist(req.params.threadId, res.locals.video, res)) return + if (!await doesVideoExist(req.params.videoId, res, 'only-video')) return + if (!await doesVideoCommentThreadExist(req.params.threadId, res.locals.video, res)) return return next() } @@ -46,7 +46,7 @@ const addVideoCommentThreadValidator = [ logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return if (!isVideoCommentsEnabled(res.locals.video, res)) return return next() @@ -62,9 +62,9 @@ const addVideoCommentReplyValidator = [ logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return if (!isVideoCommentsEnabled(res.locals.video, res)) return - if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return + if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return return next() } @@ -78,8 +78,8 @@ const videoCommentGetValidator = [ logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'id')) return - if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return + if (!await doesVideoExist(req.params.videoId, res, 'id')) return + if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return return next() } @@ -93,8 +93,8 @@ const removeVideoCommentValidator = [ logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return - if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return + if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return // Check if the user who did the request is able to delete the video if (!checkUserCanDeleteVideoComment(res.locals.oauth.token.User, res.locals.videoComment, res)) return @@ -116,7 +116,7 @@ export { // --------------------------------------------------------------------------- -async function isVideoCommentThreadExist (id: number, video: VideoModel, res: express.Response) { +async function doesVideoCommentThreadExist (id: number, video: VideoModel, res: express.Response) { const videoComment = await VideoCommentModel.loadById(id) if (!videoComment) { @@ -147,7 +147,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex return true } -async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { +async function doesVideoCommentExist (id: number, video: VideoModel, res: express.Response) { const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 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' import { getCommonVideoEditAttributes } from './videos' import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' +import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' import { CONFIG } from '../../../initializers/constants' import { CONSTRAINTS_FIELDS } from '../../../initializers' @@ -51,7 +51,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ .end() } - if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) + if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) // Check we have at least 1 required param 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 '../../../.. import { logger } from '../../../helpers/logger' import { UserModel } from '../../../models/account/user' import { areValidationErrors } from '../utils' -import { isVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' +import { doesVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' import { CONSTRAINTS_FIELDS } from '../../../initializers' import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' import { isVideoPlaylistDescriptionValid, - isVideoPlaylistExist, + doesVideoPlaylistExist, isVideoPlaylistNameValid, isVideoPlaylistPrivacyValid, isVideoPlaylistTimestampValid, @@ -17,7 +17,7 @@ import { } from '../../../helpers/custom-validators/video-playlists' import { VideoPlaylistModel } from '../../../models/video/video-playlist' import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { isVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' +import { doesVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' import { VideoModel } from '../../../models/video/video' import { authenticatePromiseIfNeeded } from '../../oauth' @@ -31,7 +31,7 @@ const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ if (areValidationErrors(req, res)) return cleanUpReqFiles(req) const body: VideoPlaylistCreate = req.body - if (body.videoChannelId && !await isVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) + if (body.videoChannelId && !await doesVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) { cleanUpReqFiles(req) @@ -52,7 +52,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ if (areValidationErrors(req, res)) return cleanUpReqFiles(req) - if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return cleanUpReqFiles(req) + if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return cleanUpReqFiles(req) const videoPlaylist = res.locals.videoPlaylist @@ -86,7 +86,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ .json({ error: 'Cannot update a watch later playlist.' }) } - if (body.videoChannelId && !await isVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) + if (body.videoChannelId && !await doesVideoChannelIdExist(body.videoChannelId, res)) return cleanUpReqFiles(req) return next() } @@ -101,7 +101,7 @@ const videoPlaylistsDeleteValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoPlaylistExist(req.params.playlistId, res)) return + if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { @@ -126,7 +126,7 @@ const videoPlaylistsGetValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoPlaylistExist(req.params.playlistId, res)) return + if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist @@ -174,8 +174,8 @@ const videoPlaylistsAddVideoValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return - if (!await isVideoExist(req.body.videoId, res, 'only-video')) return + if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return + if (!await doesVideoExist(req.body.videoId, res, 'only-video')) return const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist const video: VideoModel = res.locals.video @@ -214,8 +214,8 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return - if (!await isVideoExist(req.params.videoId, res, 'id')) return + if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return + if (!await doesVideoExist(req.params.videoId, res, 'id')) return const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist const video: VideoModel = res.locals.video @@ -282,7 +282,7 @@ const videoPlaylistsReorderVideosValidator = [ if (areValidationErrors(req, res)) return - if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return + if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist 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' import 'express-validator' import { body, param } from 'express-validator/check' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' -import { isVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' +import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' @@ -17,7 +17,7 @@ const videoUpdateRateValidator = [ logger.debug('Checking videoRate parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.id, res)) return + if (!await doesVideoExist(req.params.id, res)) return return next() } 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' import 'express-validator' import { param } from 'express-validator/check' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' -import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { VideoShareModel } from '../../../models/video/video-share' import { areValidationErrors } from '../utils' @@ -16,7 +16,7 @@ const videosShareValidator = [ logger.debug('Checking videoShare parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.id, res)) return + if (!await doesVideoExist(req.params.id, res)) return const video: VideoModel = res.locals.video 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 @@ import { body, param } from 'express-validator/check' import * as express from 'express' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' -import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { areValidationErrors } from '../utils' import { logger } from '../../../helpers/logger' import { UserModel } from '../../../models/account/user' @@ -16,7 +16,7 @@ const videoWatchingValidator = [ logger.debug('Checking videoWatching parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res, 'id')) return + if (!await doesVideoExist(req.params.videoId, res, 'id')) return const user = res.locals.oauth.token.User as UserModel 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 { isVideoOriginallyPublishedAtValid, isScheduleVideoUpdatePrivacyValid, isVideoCategoryValid, - isVideoChannelOfAccountExist, + doesVideoChannelOfAccountExist, isVideoDescriptionValid, - isVideoExist, + doesVideoExist, isVideoFile, isVideoFilterValid, isVideoImage, @@ -66,7 +66,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ const videoFile: Express.Multer.File = req.files['videofile'][0] const user = res.locals.oauth.token.User - if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) + if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) const isAble = await user.isAbleToUploadVideo(videoFile) if (isAble === false) { @@ -109,7 +109,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ if (areValidationErrors(req, res)) return cleanUpReqFiles(req) if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) - if (!await isVideoExist(req.params.id, res)) return cleanUpReqFiles(req) + if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req) const video = res.locals.video @@ -123,7 +123,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ .json({ error: 'Cannot set "private" a video that was not private.' }) } - if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) + if (req.body.channelId && !await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) return next() } @@ -162,7 +162,7 @@ const videosCustomGetValidator = (fetchType: VideoFetchType) => { logger.debug('Checking videosGet parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.id, res, fetchType)) return + if (!await doesVideoExist(req.params.id, res, fetchType)) return const video: VideoModel = res.locals.video @@ -207,7 +207,7 @@ const videosRemoveValidator = [ logger.debug('Checking videosRemove parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.id, res)) return + if (!await doesVideoExist(req.params.id, res)) return // Check if the user who did the request is able to delete the video if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.REMOVE_ANY_VIDEO, res)) return @@ -223,7 +223,7 @@ const videosChangeOwnershipValidator = [ logger.debug('Checking changeOwnership parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isVideoExist(req.params.videoId, res)) return + if (!await doesVideoExist(req.params.videoId, res)) return // Check if the user who did the request is able to change the ownership of the video if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.CHANGE_VIDEO_OWNERSHIP, res)) return @@ -272,7 +272,7 @@ const videosTerminateChangeOwnershipValidator = [ const videosAcceptChangeOwnershipValidator = [ async (req: express.Request, res: express.Response, next: express.NextFunction) => { const body = req.body as VideoChangeOwnershipAccept - if (!await isVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return + if (!await doesVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return const user = res.locals.oauth.token.User const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel -- 2.25.1