import * as express from 'express'
-import { body } from 'express-validator/check'
-import { isIdValid } from '../../../helpers/custom-validators/misc'
+import { body } from 'express-validator'
+import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
import { logger } from '../../../helpers/logger'
import { areValidationErrors } from '../utils'
import { getCommonVideoEditAttributes } from './videos'
import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
-import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
-import { CONFIG } from '../../../initializers/constants'
-import { CONSTRAINTS_FIELDS } from '../../../initializers'
+import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
+import { CONFIG } from '../../../initializers/config'
+import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
+import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
const videoImportAddValidator = getCommonVideoEditAttributes().concat([
body('channelId')
- .toInt()
+ .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'),
body('targetUrl')
.optional()
.optional()
.custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'),
body('torrentfile')
- .custom((value, { req }) => isVideoImportTorrentFile(req.files)).withMessage(
- 'This torrent file is not supported or too large. Please, make sure it is of the following type: '
- + CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.EXTNAME.join(', ')
- ),
+ .custom((value, { req }) => isVideoImportTorrentFile(req.files))
+ .withMessage(
+ 'This torrent file is not supported or too large. Please, make sure it is of the following type: ' +
+ CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.EXTNAME.join(', ')
+ ),
body('name')
.optional()
.custom(isVideoNameValid).withMessage('Should have a valid name'),
.end()
}
- if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
+ if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
// Check we have at least 1 required param
if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) {