]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/video-imports.ts
Add audit logs for video import
[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'
fbad87b0
C
10
11const videoImportAddValidator = getCommonVideoAttributes().concat([
12 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
13 body('channelId')
14 .toInt()
15 .custom(isIdValid).withMessage('Should have correct video channel id'),
16 body('name')
17 .optional()
18 .custom(isVideoNameValid).withMessage('Should have a valid name'),
19
20 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
21 logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body })
22
23 const user = res.locals.oauth.token.User
24
25 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
26 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
27
28 return next()
29 }
30])
31
fbad87b0
C
32// ---------------------------------------------------------------------------
33
34export {
516df59b 35 videoImportAddValidator
fbad87b0
C
36}
37
38// ---------------------------------------------------------------------------