Does exist
This commit is contained in:
parent
9a18a62520
commit
0f6acda116
|
@ -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()
|
||||
|
|
|
@ -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<AccountModel>
|
||||
|
||||
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<AccountModel>, res: Response, sendNotFound: boolean) {
|
||||
async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) {
|
||||
const account = await p
|
||||
|
||||
if (!account) {
|
||||
|
@ -63,9 +62,9 @@ async function isAccountExist (p: Bluebird<AccountModel>, res: Response, sendNot
|
|||
|
||||
export {
|
||||
isAccountIdValid,
|
||||
isAccountIdExist,
|
||||
isLocalAccountNameExist,
|
||||
doesAccountIdExist,
|
||||
doesLocalAccountNameExist,
|
||||
isAccountDescriptionValid,
|
||||
isAccountNameWithHostExist,
|
||||
doesAccountNameWithHostExist,
|
||||
isAccountNameValid
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue