]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/video-imports.ts
Move send video components inside a dedicated directory
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / video-imports.ts
CommitLineData
fbad87b0 1import * as express from 'express'
516df59b 2import { body } from 'express-validator/check'
fbad87b0
C
3import { isIdValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import { getCommonVideoAttributes } from './videos'
516df59b 7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
fbad87b0 8import { cleanUpReqFiles } from '../../helpers/utils'
516df59b 9import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos'
5d08a6a7 10import { CONFIG } from '../../initializers/constants'
fbad87b0
C
11
12const videoImportAddValidator = getCommonVideoAttributes().concat([
13 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
14 body('channelId')
15 .toInt()
16 .custom(isIdValid).withMessage('Should have correct video channel id'),
17 body('name')
18 .optional()
19 .custom(isVideoNameValid).withMessage('Should have a valid name'),
20
21 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
22 logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body })
23
24 const user = res.locals.oauth.token.User
25
26 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
5d08a6a7
C
27
28 if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) {
29 cleanUpReqFiles(req)
30 return res.status(409)
31 .json({ error: 'Import is not enabled on this instance.' })
32 .end()
33 }
34
fbad87b0
C
35 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
36
37 return next()
38 }
39])
40
fbad87b0
C
41// ---------------------------------------------------------------------------
42
43export {
516df59b 44 videoImportAddValidator
fbad87b0
C
45}
46
47// ---------------------------------------------------------------------------