]>
Commit | Line | Data |
---|---|---|
fbad87b0 | 1 | import * as express from 'express' |
516df59b | 2 | import { body } from 'express-validator/check' |
fbad87b0 C |
3 | import { isIdValid } from '../../helpers/custom-validators/misc' |
4 | import { logger } from '../../helpers/logger' | |
5 | import { areValidationErrors } from './utils' | |
6 | import { getCommonVideoAttributes } from './videos' | |
516df59b | 7 | import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' |
fbad87b0 | 8 | import { cleanUpReqFiles } from '../../helpers/utils' |
516df59b | 9 | import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' |
fbad87b0 C |
10 | |
11 | const 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 | ||
34 | export { | |
516df59b | 35 | videoImportAddValidator |
fbad87b0 C |
36 | } |
37 | ||
38 | // --------------------------------------------------------------------------- |