1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import { isIdValid } from '../../helpers/custom-validators/misc'
4 import { logger } from '../../helpers/logger'
5 import { areValidationErrors } from './utils'
6 import { getCommonVideoAttributes } from './videos'
7 import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
8 import { cleanUpReqFiles } from '../../helpers/utils'
9 import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos'
10 import { CONFIG } from '../../initializers/constants'
12 const videoImportAddValidator = getCommonVideoAttributes().concat([
13 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
16 .custom(isIdValid).withMessage('Should have correct video channel id'),
19 .custom(isVideoNameValid).withMessage('Should have a valid name'),
21 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
22 logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body })
24 const user = res.locals.oauth.token.User
26 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
28 if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) {
30 return res.status(409)
31 .json({ error: 'Import is not enabled on this instance.' })
35 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
41 // ---------------------------------------------------------------------------
44 videoImportAddValidator
47 // ---------------------------------------------------------------------------