2018-08-02 15:34:09 +02:00
|
|
|
import * as express from 'express'
|
2018-08-03 09:43:00 +02:00
|
|
|
import { body } from 'express-validator/check'
|
2018-08-02 15:34:09 +02:00
|
|
|
import { isIdValid } from '../../helpers/custom-validators/misc'
|
|
|
|
import { logger } from '../../helpers/logger'
|
|
|
|
import { areValidationErrors } from './utils'
|
|
|
|
import { getCommonVideoAttributes } from './videos'
|
2018-08-03 09:43:00 +02:00
|
|
|
import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
|
2018-08-02 15:34:09 +02:00
|
|
|
import { cleanUpReqFiles } from '../../helpers/utils'
|
2018-08-03 09:43:00 +02:00
|
|
|
import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos'
|
2018-08-02 15:34:09 +02:00
|
|
|
|
|
|
|
const videoImportAddValidator = getCommonVideoAttributes().concat([
|
|
|
|
body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
|
|
|
|
body('channelId')
|
|
|
|
.toInt()
|
|
|
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
|
|
|
body('name')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoNameValid).withMessage('Should have a valid name'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body })
|
|
|
|
|
|
|
|
const user = res.locals.oauth.token.User
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
|
|
|
|
if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-08-03 09:43:00 +02:00
|
|
|
videoImportAddValidator
|
2018-08-02 15:34:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|