2017-06-10 16:15:25 -04:00
|
|
|
import * as express from 'express'
|
2017-12-12 11:53:50 -05:00
|
|
|
import 'express-validator'
|
2017-11-23 11:53:38 -05:00
|
|
|
import { body, param, query } from 'express-validator/check'
|
|
|
|
import { UserRight, VideoPrivacy } from '../../../shared'
|
2017-09-15 06:17:08 -04:00
|
|
|
import {
|
2018-06-14 12:06:56 -04:00
|
|
|
isBooleanValid,
|
|
|
|
isDateValid,
|
|
|
|
isIdOrUUIDValid,
|
|
|
|
isIdValid,
|
|
|
|
isUUIDValid,
|
|
|
|
toIntOrNull,
|
|
|
|
toValueOrNull
|
|
|
|
} from '../../helpers/custom-validators/misc'
|
|
|
|
import {
|
|
|
|
isScheduleVideoUpdatePrivacyValid,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoAbuseReasonValid,
|
|
|
|
isVideoCategoryValid,
|
2018-05-11 09:10:13 -04:00
|
|
|
isVideoChannelOfAccountExist,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoDescriptionValid,
|
|
|
|
isVideoExist,
|
|
|
|
isVideoFile,
|
|
|
|
isVideoImage,
|
|
|
|
isVideoLanguageValid,
|
|
|
|
isVideoLicenceValid,
|
|
|
|
isVideoNameValid,
|
|
|
|
isVideoPrivacyValid,
|
2018-05-09 05:23:14 -04:00
|
|
|
isVideoRatingTypeValid,
|
|
|
|
isVideoSupportValid,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoTagsValid
|
2017-11-23 11:53:38 -05:00
|
|
|
} from '../../helpers/custom-validators/videos'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
|
|
|
|
import { logger } from '../../helpers/logger'
|
2017-12-05 11:46:33 -05:00
|
|
|
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { UserModel } from '../../models/account/user'
|
|
|
|
import { VideoModel } from '../../models/video/video'
|
|
|
|
import { VideoShareModel } from '../../models/video/video-share'
|
2017-10-31 10:20:35 -04:00
|
|
|
import { authenticate } from '../oauth'
|
2017-11-27 11:30:46 -05:00
|
|
|
import { areValidationErrors } from './utils'
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videosAddValidator = [
|
2017-10-16 05:43:40 -04:00
|
|
|
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage(
|
2017-10-19 04:22:07 -04:00
|
|
|
'This file is not supported. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
|
2017-10-16 05:43:40 -04:00
|
|
|
),
|
2018-02-13 12:17:05 -05:00
|
|
|
body('thumbnailfile').custom((value, { req }) => isVideoImage(req.files, 'thumbnailfile')).withMessage(
|
|
|
|
'This thumbnail file is not supported. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
|
|
|
body('previewfile').custom((value, { req }) => isVideoImage(req.files, 'previewfile')).withMessage(
|
|
|
|
'This preview file is not supported. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
2017-09-15 06:17:08 -04:00
|
|
|
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
2018-05-09 05:23:14 -04:00
|
|
|
body('category')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
|
|
|
body('licence')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
|
|
|
body('language')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
|
|
|
body('nsfw')
|
2018-06-12 14:04:58 -04:00
|
|
|
.optional()
|
2018-05-09 05:23:14 -04:00
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
2018-06-12 14:04:58 -04:00
|
|
|
body('waitTranscoding')
|
|
|
|
.optional()
|
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
|
2018-05-09 05:23:14 -04:00
|
|
|
body('description')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
|
|
|
body('support')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
|
|
|
body('tags')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
|
|
|
body('commentsEnabled')
|
2018-06-12 14:04:58 -04:00
|
|
|
.optional()
|
2018-05-09 05:23:14 -04:00
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
|
|
|
body('privacy')
|
|
|
|
.optional()
|
|
|
|
.toInt()
|
|
|
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
2018-05-11 09:10:13 -04:00
|
|
|
body('channelId')
|
|
|
|
.toInt()
|
2018-06-14 12:06:56 -04:00
|
|
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
2018-06-18 04:24:53 -04:00
|
|
|
body('scheduleUpdate')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull),
|
2018-06-14 12:06:56 -04:00
|
|
|
body('scheduleUpdate.updateAt')
|
|
|
|
.optional()
|
|
|
|
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
|
|
|
|
body('scheduleUpdate.privacy')
|
|
|
|
.optional()
|
|
|
|
.toInt()
|
|
|
|
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy'),
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
2018-02-13 12:17:05 -05:00
|
|
|
if (areErrorsInVideoImageFiles(req, res)) return
|
2018-06-14 12:06:56 -04:00
|
|
|
if (areErrorsInScheduleUpdate(req, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
const videoFile: Express.Multer.File = req.files['videofile'][0]
|
|
|
|
const user = res.locals.oauth.token.User
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2018-05-16 05:33:11 -04:00
|
|
|
if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
const isAble = await user.isAbleToUploadVideo(videoFile)
|
|
|
|
if (isAble === false) {
|
|
|
|
res.status(403)
|
|
|
|
.json({ error: 'The user video quota is exceeded with this video.' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let duration: number
|
|
|
|
|
|
|
|
try {
|
|
|
|
duration = await getDurationFromVideoFile(videoFile.path)
|
|
|
|
} catch (err) {
|
2018-03-26 09:54:13 -04:00
|
|
|
logger.error('Invalid input file in videosAddValidator.', { err })
|
2017-11-27 11:30:46 -05:00
|
|
|
res.status(400)
|
|
|
|
.json({ error: 'Invalid input file.' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
videoFile['duration'] = duration
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosUpdateValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2018-02-13 12:17:05 -05:00
|
|
|
body('thumbnailfile').custom((value, { req }) => isVideoImage(req.files, 'thumbnailfile')).withMessage(
|
|
|
|
'This thumbnail file is not supported. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
|
|
|
body('previewfile').custom((value, { req }) => isVideoImage(req.files, 'previewfile')).withMessage(
|
|
|
|
'This preview file is not supported. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
2018-05-09 05:23:14 -04:00
|
|
|
body('name')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoNameValid).withMessage('Should have a valid name'),
|
|
|
|
body('category')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
|
|
|
body('licence')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
|
|
|
body('language')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
|
|
|
body('nsfw')
|
|
|
|
.optional()
|
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
2018-06-12 14:04:58 -04:00
|
|
|
body('waitTranscoding')
|
|
|
|
.optional()
|
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
|
2018-05-09 05:23:14 -04:00
|
|
|
body('privacy')
|
|
|
|
.optional()
|
|
|
|
.toInt()
|
|
|
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
|
|
|
body('description')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
|
|
|
body('support')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
|
|
|
body('tags')
|
|
|
|
.optional()
|
2018-05-16 03:28:18 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
|
|
|
body('commentsEnabled')
|
|
|
|
.optional()
|
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
2018-05-11 09:10:13 -04:00
|
|
|
body('channelId')
|
|
|
|
.optional()
|
|
|
|
.toInt()
|
|
|
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
2018-06-18 04:24:53 -04:00
|
|
|
body('scheduleUpdate')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull),
|
2018-06-14 12:06:56 -04:00
|
|
|
body('scheduleUpdate.updateAt')
|
|
|
|
.optional()
|
|
|
|
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
|
|
|
|
body('scheduleUpdate.privacy')
|
|
|
|
.optional()
|
|
|
|
.toInt()
|
|
|
|
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy'),
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosUpdate parameters', { parameters: req.body })
|
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
2018-02-13 12:17:05 -05:00
|
|
|
if (areErrorsInVideoImageFiles(req, res)) return
|
2018-06-14 12:06:56 -04:00
|
|
|
if (areErrorsInScheduleUpdate(req, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
|
|
|
|
|
|
|
const video = res.locals.video
|
|
|
|
|
2018-02-22 03:03:45 -05:00
|
|
|
// Check if the user who did the request is able to update the video
|
2018-05-11 09:10:13 -04:00
|
|
|
const user = res.locals.oauth.token.User
|
|
|
|
if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) {
|
|
|
|
return res.status(409)
|
2018-06-15 10:52:15 -04:00
|
|
|
.json({ error: 'Cannot set "private" a video that was not private.' })
|
2017-11-27 11:30:46 -05:00
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
2018-05-16 05:33:11 -04:00
|
|
|
if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return
|
2018-05-11 09:10:13 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2016-02-04 15:10:33 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videosGetValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosGet parameters', { parameters: req.params })
|
2016-12-29 13:07:05 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
const video = res.locals.video
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2018-01-31 08:40:42 -05:00
|
|
|
// Video is public, anyone can access it
|
|
|
|
if (video.privacy === VideoPrivacy.PUBLIC) return next()
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2018-01-31 08:40:42 -05:00
|
|
|
// Video is unlisted, check we used the uuid to fetch it
|
|
|
|
if (video.privacy === VideoPrivacy.UNLISTED) {
|
|
|
|
if (isUUIDValid(req.params.id)) return next()
|
|
|
|
|
|
|
|
// Don't leak this unlisted video
|
|
|
|
return res.status(404).end()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Video is private, check the user
|
2017-11-27 11:30:46 -05:00
|
|
|
authenticate(req, res, () => {
|
|
|
|
if (video.VideoChannel.Account.userId !== res.locals.oauth.token.User.id) {
|
|
|
|
return res.status(403)
|
|
|
|
.json({ error: 'Cannot get this private video of another user' })
|
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
]
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videosRemoveValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosRemove parameters', { parameters: req.params })
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
|
|
|
|
|
|
|
// Check if the user who did the request is able to delete the video
|
2018-02-22 03:03:45 -05:00
|
|
|
if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.REMOVE_ANY_VIDEO, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videosSearchValidator = [
|
2017-12-05 11:46:33 -05:00
|
|
|
query('search').not().isEmpty().withMessage('Should have a valid search'),
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videosSearch parameters', { parameters: req.params })
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videoAbuseReportValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2017-09-15 06:17:08 -04:00
|
|
|
body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videoRateValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2017-09-15 06:17:08 -04:00
|
|
|
body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'),
|
2017-03-08 15:35:43 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videoRate parameters', { parameters: req.body })
|
2017-03-08 15:35:43 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2017-03-08 15:35:43 -05:00
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
const videosShareValidator = [
|
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
|
|
|
param('accountId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid account id'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videoShare parameters', { parameters: req.params })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
if (!await isVideoExist(req.params.id, res)) return
|
2017-11-27 08:44:51 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
const share = await VideoShareModel.load(req.params.accountId, res.locals.video.id, undefined)
|
2017-11-27 08:44:51 -05:00
|
|
|
if (!share) {
|
|
|
|
return res.status(404)
|
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoShare = share
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
export {
|
|
|
|
videosAddValidator,
|
|
|
|
videosUpdateValidator,
|
|
|
|
videosGetValidator,
|
|
|
|
videosRemoveValidator,
|
|
|
|
videosSearchValidator,
|
2017-11-27 08:44:51 -05:00
|
|
|
videosShareValidator,
|
2017-05-15 16:22:03 -04:00
|
|
|
|
|
|
|
videoAbuseReportValidator,
|
|
|
|
|
2017-10-10 04:02:18 -04:00
|
|
|
videoRateValidator
|
2017-05-15 16:22:03 -04:00
|
|
|
}
|
2016-12-29 13:07:05 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-02-22 03:03:45 -05:00
|
|
|
function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: UserRight, res: express.Response) {
|
2017-04-26 15:22:10 -04:00
|
|
|
// Retrieve the user who did the request
|
2017-11-27 11:30:46 -05:00
|
|
|
if (video.isOwned() === false) {
|
|
|
|
res.status(403)
|
2018-05-16 05:33:11 -04:00
|
|
|
.json({ error: 'Cannot manage a video of another server.' })
|
2017-10-31 10:20:35 -04:00
|
|
|
.end()
|
2017-11-27 11:30:46 -05:00
|
|
|
return false
|
2017-10-31 10:20:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user can delete the video
|
2018-01-04 05:19:16 -05:00
|
|
|
// The user can delete it if he has the right
|
2017-11-10 08:48:08 -05:00
|
|
|
// Or if s/he is the video's account
|
2017-11-27 11:30:46 -05:00
|
|
|
const account = video.VideoChannel.Account
|
2018-02-22 03:03:45 -05:00
|
|
|
if (user.hasRight(right) === false && account.userId !== user.id) {
|
2017-11-27 11:30:46 -05:00
|
|
|
res.status(403)
|
2018-05-16 05:33:11 -04:00
|
|
|
.json({ error: 'Cannot manage a video of another user.' })
|
2017-10-31 10:20:35 -04:00
|
|
|
.end()
|
2017-11-27 11:30:46 -05:00
|
|
|
return false
|
2017-10-31 10:20:35 -04:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
return true
|
2017-04-26 15:22:10 -04:00
|
|
|
}
|
2018-02-13 12:17:05 -05:00
|
|
|
|
|
|
|
function areErrorsInVideoImageFiles (req: express.Request, res: express.Response) {
|
|
|
|
// Files are optional
|
|
|
|
if (!req.files) return false
|
|
|
|
|
|
|
|
for (const imageField of [ 'thumbnail', 'preview' ]) {
|
|
|
|
if (!req.files[ imageField ]) continue
|
|
|
|
|
|
|
|
const imageFile = req.files[ imageField ][ 0 ] as Express.Multer.File
|
|
|
|
if (imageFile.size > CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max) {
|
|
|
|
res.status(400)
|
2018-06-14 12:06:56 -04:00
|
|
|
.json({ error: `The size of the ${imageField} is too big (>${CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max}).` })
|
2018-02-13 12:17:05 -05:00
|
|
|
.end()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2018-06-14 12:06:56 -04:00
|
|
|
|
|
|
|
function areErrorsInScheduleUpdate (req: express.Request, res: express.Response) {
|
|
|
|
if (req.body.scheduleUpdate) {
|
|
|
|
if (!req.body.scheduleUpdate.updateAt) {
|
|
|
|
res.status(400)
|
|
|
|
.json({ error: 'Schedule update at is mandatory.' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|