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